Question: In C++ i need to create an array of pointers in the base type, then randomly populate it with references to instances of person, employee

In C++

i need to create an array of pointers in the base type, then randomly populate it with references to instances of person, employee and faculty objects. Give all fields in each object relevant values and in a for loop invoke tostring() on these instances to demonstrate that it is polymorphic how do i change my code ?

#include

#include using namespace std;

class Person

{

public:

string name;

string address;

virtual void toString()

{

}

};

class Employee:public Person

{

public:

stringofficeLocation;

double slary;

};

class Faculty:public Employee

{

public:

int hours;

int rank;

void toString()

{

cout<<"Person Name\t"<<"\t"<

cout<<"OfficeLocation\t"<<"\t"<

cout<<"Office Hours"<<"\t"<

}

};

int main()

{

Person p;

Faculty fp;

cout<<"Enter Person Name ";

cin>>fp.name;

cout<<" Enter Person Address ";

cin>>fp.address;

cout<<" Enter Employee Office Location ";

cin>>fp.officeLocation;

cout<<" Enter Employee Salary ";

cin>>fp.slary;

cout<<" Enter Faculty Hours ";

cin>>fp.hours;

cout<<" Enter Faculty Rank ";

cin>>fp.rank;

cout<< endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!