using namespace std;
struct Date {
int month, year;
};
class Person {
protected:
string name, department;
public:
Person() {
name = "";
department = "";
}
Person(string n, string d) {
name = n, department = d;
}
void print() {
cout < "name:="" "="">< name=""><>
cout < "department:="" "="">< department=""><>
}
string getName() {
return name;
}
string getDepartment() {
return department;
}
~Person() {
cout <>
}
};
class Student : public Person {
protected:
Date graduationDate;
public:
Student() {
graduationDate.month = 0;
graduationDate.year = 0;
}
Student(string n, string d, Date date) {
name = n, department = d;
graduationDate = date;
}
void setGraduationDate(Date d) {
graduationDate = d;
}
Date getGraduationDate() {
return graduationDate;
}
int timeToGraduation(Date today) {
if (today.month > graduationDate.month) {
return ((graduationDate.year - today.year - 1) * 12 +
(12 - today.month) + graduationDate.month);
}
else {
return ((graduationDate.year - today.year) * 12 +
abs(today.month - graduationDate.month));
}
}
void print() {
cout < "name:="" "="">< name=""><>
cout < "department:="" "="">< department=""><>
cout < "graduation="" date:="" "="">< graduationdate.month="">< "/"="">< graduationdate.year=""><>
}
};
class Faculty : public Person {
protected:
Date startDate;
string title;
public:
Faculty(string n, string d, string t, Date date) {
name = n, department = d, title = t;
startDate = date;
}
void setTitle(string t) {
title = t;
}
void setStartDate(Date d) {
startDate = d;
}
string getTitle() {
return title;
}
Date getStartDate() {
return startDate;
}
void print() {
cout < "name:="" "="">< name=""><>
cout < "department:="" "="">< department=""><>
cout < "title:="" "="">< title=""><>
cout < "start="" date:="" "="">< startdate.month="">< "/"="">< startdate.year=""><>
}
};
class Intern : public Student {
protected:
string company;
double salary;
public:
Intern(string n, string d, Date date, string c, double s) {
name = n, department = d;
graduationDate = date;
company = c;
salary = s;
}
void setSalary(double s) {
salary = s;
}
void setCompany(string c) {
company = c;
}
string getCompany() {
return company;
}
double getSalary() {
return salary;
}
void print() {
cout < "name:="" "="">< name=""><>
cout < "department:="" "="">< department=""><>
cout < "company:="" "="">< company=""><>
cout < "salary:="" "="">< salary=""><>
cout < "graduation="" date:="" "="">< graduationdate.month="">< "/"="">< graduationdate.year=""><>
}
};
int main() {
Date today, graduation;
today.month = 3;
today.year = 2021;
graduation.month = 10;
graduation.year = 2027;
Student John("John Smith", "Computer Science", graduation);
Faculty Chris("Chris Smith", "Computer Science", "Associate Professor", today);
Intern Bob("Bob Smith", "Computer Science", graduation, "Apple", 60000.0);
Student* studentArray = new Student[10];
John.print();
cout < "time="" for="" john="" to="" graduate:="" "="">< john.timetograduation(today)="">< "="">
cout <>
Chris.print();
cout <>
Bob.print();
cout < "time="" for="" bob="" to="" graduate:="" "="">< bob.timetograduation(today)="">< "="">
return 0;
}