You have been given a Person class and a Student class which
You have been given a Person class and a Student class which inherits from it. Create a simple Faculty class that also inherits from the Person class, such that both Student and Faculty pointers can be stored in a single vector. Your Faculty class should have a string for the name of the faculty member, and a string for the department they belong to. Your class should also implement the toString function required by the Person class. Follow the same format as the Student toString function. When your program is run, you will be given 2 sets of 3 inputs which you should use to create the appropriate objects: a string representing the type (\"student\" or \"faculty\"), a string for the name of the person, and either a double GPA for a student, or a string representing a department for a faculty. Create pointers to the appropriate objects and store them both in a single vector called my_list.
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
class Person
{
public:
Person(string name);
virtual string toString() = 0;
protected:
string name;
};
void printList(vector<Person*> list);
Person::Person(string name)
{
this->name = name;
}
class Student : public Person
{
public:
Student(string name, double GPA);
string toString();
private:
double GPA;
};
Student::Student(string name, double GPA) : Person(name)
{
this->GPA = GPA;
}
string Student::toString()
{
stringstream ss;
ss << \"Name: \" << name << endl;
ss << \"GPA: \" << GPA << endl;
return ss.str();
}
//
// Create your faculty class here
//
int main()
{
//Code here
printList(my_list);
return 0;
}
void printList(vector<Person*> list)
{
for (int i = 0; i < list.size(); i++)
{
cout << list[i]->toString();
}
}
Solution
#include \"Student.h\"
#include <iostream>
using namespace std;
Student :: Student()
{
ID = 0;
name = \"\";
GPA = 0;
gender = \' \';
}
Student :: Student(int ID, string name, double GPA, char gender)
{
this -> ID = ID;
this -> name = name;
this -> GPA = GPA;
this -> gender = gender;
}
void Student :: setStudent(int ID, string name, double GPA, char gender)
{
this -> ID = ID;
this -> name = name;
this -> GPA = GPA;
this -> gender = gender;
}
int Student :: getID()
{
return ID;
}
string Student :: getName()
{
return name;
}
double Student :: getGPA()
{
return GPA;
}
char Student :: getGender()
{
return gender;
}
void Student :: print()
{
cout << \"ID : \" << ID << endl;
cout << \"Name : \" << name << endl;
cout << \"GPA : \" << GPA << endl;
cout << \"Gender : \" << gender << endl;
}


