Using the base class Person which has two member variables called name and birthday [both of type string], derive two separate classes from Person, called Student and Professor. The Student class has a major [string] and a gpa [double] and the Professor class has research [string] and a salary [double].
Write two constructors for each of the three classes; in each case one will be the no-argument constructor, and the other constructor will initialize all member variables for that particular class.
Page 3 of 4
Create/write the void print() function for each of the three classes; this will print out the all the available information about each object type.
class Person //base class Person
{
public:
void print() const
{
cout <<"This is the Person Class.n";
}
private:
string name;
string birthday;
};
class Student : public Person //class Student derived from Person
{
public:
string major;
double gpa;
void print() const
{
cout <<"Hello my Major is Engineering.n";
}
private:
};
class Professor : public Person //class professor derived from Person
{
public:
string research;
double salary;
void print() const
{
cout <<"Hello my Research is in the field of Fluids.n";
}
private:
};
--------------------------------------------------------------------------------------------------
Im having problems figuring out certain things.
1 - Am i deriving the member variables correctly? If not how should it be done?
2 - Im not sure how to do this.
"write two constructors for each of the three classes; in each case one will be the no-argument constructor, and the other constructor will initialize all member variables for that particular class."
3 - Where do the "Create/write the void print() function for each of the three classes" go? I know how to use them just don't know where they belong.
Any help is appreciative. Thank you. Ive been reading alot on classes and Inheritance but i just don't seem to understand it :(