#include <string>
#include <iostream>
#include <vector>
using namespace std;
class Person {
public:
Person();
Person(string n, string a, string tel, string em);
string getName();
string getAddress();
string getTel();
string getEmail();
virtual string whatAmI();
private:
string name, address, telephone, email;
};
Person::Person() {
}
Person::Person(string n, string a, string tel, string em) {
name = n;
address = a;
telephone = tel;
email = em;
}
string Person::getName() {
return name;
}
string Person::getAddress() {
return address;
}
string Person::getTel() {
return telephone;
}
string Person::getEmail() {
return email;
}
string Person::whatAmI() {
return "Person";
}
//Class Student derived from Person
class Student: virtual public Person {
public:
Student(string n, string a, string tel, string em, string cstat);
virtual string whatAmI();
private:
string classStatus;
};
Student::Student(string n, string a, string tel, string em, string cstat):
Person(n, a, tel, em), classStatus(cstat) {
}
string Student::whatAmI() {
return "Student";
}
//Class Employee derived from Person
class Employee: public Person {
public:
Employee(string n, string a, string tel, string em, string of, double sal, string date);
virtual string whatAmI();
private:
string office, dateHired;
double salary;
};
Employee::Employee(string n, string a, string tel, string em, string of, double sal, string date):
Person(n, a, tel, em), office(of), salary(sal), dateHired(date) {
}
string Employee::whatAmI() {
return "Employee";
}
//Class Faculty derived from Employee
class Faculty: public Employee {
public:
Faculty(string n, string a, string tel, string em, string of, double sal, string date, string fr, string fstat);
virtual string whatAmI();
private:
string frank, fstatus;
};
Faculty::Faculty(string n, string a, string tel, string em, string of, double sal, string date, string fr, string fstat):
Employee(n, a, tel, em, of, sal, date), frank(fr), fstatus(fstat) {
}
string Faculty::whatAmI() {
return "Faculty";
}
//Class Staff derived from Employee
class Staff: public Employee {
public:
Staff(string n, string a, string tel, string em, string of, double sal, string date, string title);
virtual string whatAmI();
private:
string jobtitle;
};
Staff::Staff(string n, string a, string tel, string em, string of, double sal, string date, string title):
Employee(n, a, tel, em, of, sal, date), jobtitle(title) {
}
string Staff::whatAmI() {
return "Staff";
}
class StaffST: public Staff, public Student {
public:
StaffST(string n, string a, string tel, string em, string of, double sal , string date, string title, string cstat, int chours);
virtual string whatAmI();
private:
int credithrs;
};
StaffST::StaffST(string n, string a, string tel, string em, string of, double sal , string date, string title, string cstat, int chours):
Staff(n, a, tel, em, of, sal, date, title), Student(n, a, tel, em, cstat), credithrs(chours) {
}
string StaffST::whatAmI() {
return "StaffST";
}
string classify(Person* p) {
return p->whatAmI();
}
int main () {
vector<Person*> v;
v.push_back(new Person("John Adams","Boston","617-555-0000","john@adams.com"));
v.push_back(new Student("John Quincy Adams","Boston","617-555-0000","johnq@adams.com","senior"));
v.push_back(new Faculty("John Doe", "123 Citrus Dr.", " 909-255-0002","Jdoe@email.com", " Room 354", 46000, "January 24,2011", "Professor", "Tenured"));
v.push_back(new Employee("John Smith", "123 coyote Dr.", " 909-255-0001", "john@yahoo.com", "Jack Brown 385", 50000, "June 13, 2005"));
v.push_back(new Staff("Samuel Adams","Boston","617-555-BEER","sam@adams.com","brewhouse 1",25000," 5-3-08","Brewer"));
v.push_back(new StaffST("Samuel Smith","Boston","617-555-BEER","samsmith@adams.com","brewhouse 5",100,"9-15-1774","Taster","junior", 12));
// Hey - no Faculty object ---> add one yourself!
for (int i = 0; i < v.size(); i++)
{
cout << v[i]->getName() << " " << classify(v[i]) << endl;
}
return 0;
}
I get an error that says "Person" is an ambiguous base of "StaffST"