So here is my very long (I apologize) list of classes. There are two things I need to do
1. Create the virtual string function whatami() for the Person class. The function returns the type of class - Person, Faculty, Staff, etc. Note that you must create a separate function for each derivedclass.
2. Write a string function classify which accepts a Person pointer variable as an argument and returns the output from whatami().
Can anyone help, it would be greatly appreciated. Thank you in advance
class Student : public Person
{
public:
Student();
Student(string n, string a, string t, string e, string s);
string getStatus();
private:
string status;
};
Student::Student()
:Person()
{
status = "default_status";
}
Student::Student(string n, string a, string t, string e, string s)
:Person(n,a,t,e)
{
status = s;
}
string Student::getStatus()
{
return status;
}
class Employee : public Person
{
public:
Employee();
Employee(string n, string a, string t, string e, string o, string w, string h);
string getOffice();
string getWages();
string getHired();
Employee::Employee(string n, string a, string t, string e, string o, string w, string h)
:Person(n,a,t,e)
{
office = o;
wages = w;
hired = h;
}
string Employee::getOffice()
{
return office;
}
string Employee::getWages()
{
return wages;
}
string Employee::getHired()
{
return hired;
}
class Faculty : public Employee
{
public:
Faculty();
Faculty(string n, string a, string t, string e, string o, string w, string h, string r, string s);
string getRank();
string getStatus();
private:
string rank;
string status;
};
Faculty::Faculty()
:Employee()
{
rank = "default_rank";
status = "default_status";
}
Faculty::Faculty(string n, string a, string t, string e, string o, string w, string h, string r, string s)
:Employee(n,a,t,e,o,w,h)
{
rank = r;
status = s;
}
string Faculty::getRank()
{
return rank;
}
string Faculty::getStatus()
{
return status;
}
class Staff : public Employee
{
public:
Staff();
Staff(string n, string a, string t, string e, string o, string w, string h, string p);
string getPosition();
private:
string position;
};
Staff::Staff()
:Employee()
{
position = "default_position";
}
Staff::Staff(string n, string a, string t, string e, string o, string w, string h, string p)
:Employee(n,a,t,e,o,w,h)
{
position = p;
}
string Staff::getPosition
{
return position;
}
class StaffST : public Student, public Staff
{
public:
StaffST();
StaffST(string n, string a, string t, string e, string o, string w, string h, string p, int c)
int getCreditHours();
StaffST::StaffST(string n, string a, string t, string e, string o, string w, string h, string p, int c)
:Student(n,a,t,e,s), Staff(n,a,t,e,o,w,h,p)
{
credithours = c;
}
int StaffST::getCreditHours()
{
return credithours;
}
This looks like an assignment from the same class I am in and I am having trouble as well.
1. Create a new class StaffST which has Staff and Student as base classes. StaffSt has an additional attribute (int) credithours.
2. Create the virtual string function whatami() for the Person class. The function returns the type of class - Person, Faculty, Staff, etc. Note that you must create a separate function for each derivedclass.
3. Write a string function classify which accepts a Person pointer variable as an argument and returns the output from whatami().
4. Write a test main program that creates a vector of pointers to Person. Creat a Person, Student, Employee, Faculty, Staff and StaffST object and add pointers to these objects to your vector. Now use the function classify to output the type of each object from the vector pointers.
I am having trouble with a couple of things:
In part 1 I get " error: ‘Person’ is an ambiguous base of ‘StaffST’ "
I think I got part 2 but since I cannot seem to figure out how to create the classify function I cannot check that
In part 3 I have no idea how or where to write the classify function so any help would be appreciated
This is my code:
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
class Faculty : public Employee{
public:
Faculty();
Faculty(string n, string a, string p, string e, string o, string s, string h, string r, string st);
string getrank(){return rank;}
string getstatus(){return status;}
virtual string whatami(){return "Faculty";}
private:
string rank;
string status;
};
Faculty::Faculty():Employee(){
rank = "rank";
status = "status";
}
Faculty::Faculty(string n, string a, string p, string e, string o, string s, string h, string r, string st):Employee(n, a, p, e, o, s, h){
rank = r;
status = st;
}
#endif
class StaffST : public Student, public Staff{
public:
StaffST();
StaffST(string n, string a, string p, string e, string i, string y, string o, string s, string h, string pos, int ch);
int getcredithours(){return credithours;}
virtual string whatami(){return "StaffST";}
private:
int credithours;
};
StaffST::StaffST(){
credithours = 0;
}
StaffST::StaffST(string n, string a, string p, string e, string i, string y, string o, string s, string h, string pos, int ch):Student(n, a, p, e, i, y),Staff(n, a, p, e, o, s, h, pos){
credithours = ch;
}
#endif
I'm still new to this. But to get around the ambiguity I think it has something to do with declaring whether you want it to use Staff's or Student's Person.
like if its
I tried the virtual inheritance, but would get a run time error. I couldn't find much that explained how to implement the virtual inheritance well. Like I said I'm new to c++ so I was probably doing something off.