In: Computer Science
// File name: Person.h
// Person class declaration. Person is the base class.
#pragma once
#include <iostream>
using namespace std;
class Person {
private:
string fName;
string lName;
int birthYear;
int birthMonth;
int birthDay;
public:
Person();
void setName(string, string);
void setBirthDate(int, int, int);
string getFullName();
string getBirthDate();
};
// File name: Person.cpp
// Person class definition. Person is the base class.
#include "Person.h"
Person::Person() {
fName = "";
lName = "";
birthYear = 0;
birthMonth = 0;
birthDay = 0;
}
void Person::setName(string first, string last) {
fName = first;
lName = last;
}
void Person::setBirthDate(int year, int month, int day) {
birthYear = year;
birthMonth = month;
birthDay = day;
}
string Person::getFullName() {
return fName + lName;
}
// This method creates a string with the birth date
// using the following format: month/day/year
// where month and day are 2-digit values
// and year is a 4-digit value
string Person::getBirthDate() {
// define the method
}
// File name: Student.h
// Student class declaration. Student inherits from Person
#pragma once
// make sure to indicate the inheritance
class Student {
private:
string idNumber;
string major;
static string masterIdNumber;
public:
Student();
Student(string, string);
Student(string, string, string);
void setMajor(string);
void printStudent();
};
// File name: Student.cpp
// Student class definition. Student inherits from Person
#include "Student.h"
string Student::masterIdNumber = "20200000";
// the defaul constrcuctor initializes major to the empty string
// It adds 1 to the masterIdNumber, and assigns the resulting value
// to idNumber
Student::Student() {
}
// This constructor takes the first and last names of the student as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting value
// to idNumber
Student::Student(string, string) {
}
// This constructor receives the student's first name, last name, and major as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting value
// to idNumber
Student::Student(string, string, string) {
}
// This methods receives a string as parameter
// and assigns the value to the major field
void Student::setMajor(string) {
}
// This method will print the students information ín a table-like manner
// The format to be printed is:
// ID Number Name Major Date of Birth
// Make sure to allow enough space for each column
void Student::printStudent() {
}
// File name: chapter10.cpp
// Follow the instructions to implement the class
int main() {
// declare a student, named s1, using the default constructor
// asign the name Vilma Picapiedra, date of birth May 10, 1998, and major Computer Science
// declare a student, named s2, using Betty Marmol as parameters
// asign date of birth June 11, 1999, and major Computer Engineering
// declare a student, named s3, using Pablo Marmol and Electrical Engineering as parameters
// assign date of birth December 9, 1990
// delcare a stydent, named s4, using any of the constructors
// this student has the following information:
// Name: Pedro Picapiedra, date of birth January 10, 1995, major Computer Engineering
// print a table with all students
// the table headers are: Student ID, Name, Major, Date of Birth
system("pause");
return 0;
}
//C++ Code
/*========Person.h================*/
#pragma once
#include <iostream>
#include<iomanip>
using namespace std;
class Person {
private:
string fName;
string lName;
int birthYear;
int birthMonth;
int birthDay;
public:
Person();
void setName(string, string);
void setBirthDate(int, int, int);
string getFullName();
string getBirthDate();
};
// File name:
Person.cpp
// Person class definition. Person is the base class.
#include "Person.h"
#include <sstream>
Person::Person() {
fName = "";
lName = "";
birthYear = 0;
birthMonth = 0;
birthDay = 0;
}
void Person::setName(string first, string last) {
fName = first;
lName = last;
}
void Person::setBirthDate(int year, int month, int day) {
birthYear = year;
birthMonth = month;
birthDay = day;
}
string Person::getFullName() {
return fName +" "+ lName;
}
// This method creates a string with the birth date
// using the following format: month/day/year
// where month and day are 2-digit values
// and year is a 4-digit value
string Person::getBirthDate() {
// define the method
ostringstream s1;
s1 << setw(2) << setfill('0') << birthMonth
<< "/" << setw(2) << setfill('0') <<
birthDay << "/" << setw(4) << setfill('0')
<< birthYear;
return s1.str();
}
// File name: Student.h
// Student class declaration. Student inherits from Person
#pragma once
#include"Person.h"
// make sure to indicate the inheritance
class Student :public Person{
private:
string idNumber;
string major;
static long int masterIdNumber;
public:
Student();
Student(string, string);
Student(string, string, string);
void setMajor(string);
void printStudent();
};
// File name:
Student.cpp
// Student class definition. Student inherits from Person
#include "Student.h"
#include<string>
long int Student::masterIdNumber = 20200000;
// the defaul constrcuctor initializes major to the empty
string
// It adds 1 to the masterIdNumber, and assigns the resulting
value
// to idNumber
Student::Student() :Person(){
major = "";
masterIdNumber += 1;
idNumber = to_string(masterIdNumber);
}
// This constructor takes the first and last names of the student
as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting
value
// to idNumber
Student::Student(string first, string last) {
Person::setName(first, last);
masterIdNumber +=1;
idNumber = to_string(masterIdNumber);
}
// This constructor receives the student's first name, last name,
and major as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting
value
// to idNumber
Student::Student(string first, string last , string m) {
Person::setName(first, last);
major = m;
masterIdNumber += 1;
idNumber = to_string(masterIdNumber);
}
// This methods receives a string as parameter
// and assigns the value to the major field
void Student::setMajor(string m) {
major = m;
}
// This method will print the students information ín a table-like
manner
// The format to be printed is:
// ID Number Name Major Date of Birth
// Make sure to allow enough space for each column
void Student::printStudent() {
cout << left << setw(10) <<
idNumber<<left<<setw(20)<<getFullName() <<
left << setw(30) << major << right <<
setw(10) << getBirthDate()
<< endl;
}
// File name:
chapter10.cpp
// Follow the instructions to implement the class
#include"Student.h"
int main() {
// declare a student, named s1, using the default constructor
Student s1;
// asign the name Vilma Picapiedra, date of birth May 10, 1998,
and major Computer Science
s1.setName("Vilma", "Picapiedra");
s1.setBirthDate(1998,5,10);
s1.setMajor("Computer Science");
// declare a student, named s2, using Betty Marmol as
parameters
Student s2("Betty", "Marmol");
// asign date of birth June 11, 1999, and major Computer
Engineering
s2.setBirthDate(1999,6,11);
s2.setMajor("Computer Engineering");
// declare a student, named s3, using Pablo Marmol and Electrical
Engineering as parameters
Student s3("Pablo", "Marmol", "Electrical Engineering");
// assign date of birth December 9, 1990
s3.setBirthDate(1990,12,9);
// delcare a stydent, named s4, using any of the
constructors
Student s4;
// this student has the following information:
// Name: Pedro Picapiedra, date of birth January 10, 1995, major
Computer Engineering
s4.setName("Pedro", "Picapiedra");
s4.setBirthDate( 1995,1,10);
s4.setMajor("Computer Engineering");
// print a table with all students
// the table headers are: Student ID, Name, Major, Date of
Birth
//header
cout << left << setw(15) << "ID Number" <<
left << setw(25) << "Name"
<< left << setw(20) << "Major" << right
<< setw(10) << "Birth Date"
<< endl;
cout <<
"======================================================================="
<< endl;
s1.printStudent();
s2.printStudent();
s3.printStudent();
s4.printStudent();
system("pause");
return 0;
}
//Output
//If you need any help regarding this solution...... please,.... leave a comment..... thanks