I have a homework problem that asks:
Desgin a derived class GraduateStudent from base class Student. It adds a data member named Advisor to store the name of student’s thesis advisor. Provide constructor, destructor, accessor, and modifier functions. This class overrides the year function to returns one of two strings (“Masters” or “PhD”) depending on the number of hours completed, using using the chart below.
Hours Year
<=30 Masters
(greater than) 30 PhD
I've written:
using namespace std;
class Student
{
public:
Student( string s = "", int h = 0);
~Student();
string getName() const;
int getHours() const;
void setName(string s);
void setHours (int h);
string year () const;
private:
string name;
int hours;
};
class GraduateStudent: private Student
{
public:
GraduateStudent(string s = "", int h=0, string advisor=""); //constructor
~GraduateStudent(); //destructor
string getAdvisor();
void setAdvisor(string advisor);
//Class overrides??
private:
string Advisor;
}
The class student was given, I've added the Graduate Student derived class.
My question is first if I have set up the derived class properly. My second question is how can I override the year function without if statements? I tried to use those statements but the editor gave me errors, I suspect since its a header file.