Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise P19.7. Change the C++ class TeachingAssistant to use nested classes. Ad

ID: 3536763 • Letter: E

Question

Exercise P19.7. Change the C++ class TeachingAssistant to use nested classes. Add a member function as_employee to the class TeachingAssistant that will return an object of type Employee, and the member function as_student that will, from this value, return the Student object. Again show how to use the same value on a list of Students and a list of Employees. Is this technique easier or more difficult to use than the multiple inheritance technique?


We can define a teaching assistant class as follows:

class TeachingAssistant : public Employee, public Student

{

...

}


Explanation / Answer

#include <iostream>

#include "Employees.h"

#include "Students.h"


#include <string>

using namespace std;



class TeachingAssistants : public Students, public Employees

{

public:

string get_id();

string student_id();

string employee_id();


};


string TeachingAssistants :: get_id()

{

return Employees :: get_id();

}

string TeachingAssistants :: student_id()

{

return Students :: get_id();

}


int main()


{

//Declaring integers


TeachingAssistants* fred = new as_employee();





cout<<"Your teaching assistant is "<<fred->Employees::get_id()<<" ";


TeachingAssistants* cathy = new as_students();


cout<<"Your new teaching assistant is "<<cathy-<Students::get_id()" ";




system("PAUSE");

return EXIT_SUCCESS;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote