Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago