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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started