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

In the Module 06 Programming Assignment (Inheritance Proved) you created a progr

ID: 3838603 • Letter: I

Question

In the Module 06 Programming Assignment (Inheritance Proved) you created a program for a class Person and a class Student. Reuse those two classes for this assignment and build upon them as follows:

Add another class Professional that inherits the Person class and overrides the display() method.

Enhance all three classes to use Polymorphism on the display() method.

In the main() method, use a polymorphic pointer variable pIndividual of type Person to call the corresponding display()method of all the three classes.

Explanation / Answer

#include <iostream>
#include <stdio.h>

using namespace std;

class Person
{
protected:
char name[15];
char gender[6];
public:
void getData()
{
cout<<" Enter Name:";
cin>>name;
cout<<" Enter Gender:";
cin>>gender;
}
void display()
{
cout<<" Name:" <<name <<endl;
cout<<" Gender:" <<gender <<endl;
}
};
class Student: public Person
{
protected:
char school_name[15], grade[5];
public:
void getData()
{
cout<<" Enter The School name:";
cin>>school_name;
cout<<" Enter Your Grade:";
cin>>grade;
}
void display()
{
cout<<" School Name:"<<school_name<<endl;
cout<<" School Grade:" <<grade <<endl;
}
};
class Professional: public Person
{
private:
char profession[15];
int age;
public:
void getData()
{
cout<<" Enter Your Profession:";
cin>>profession;
cout<<" Enter Your age at the time of Profession:";
cin>>age;
}
void display()
{
cout<<" Profession:"<<profession<<endl;
cout<<" Age:" <<age <<endl;
}
};
int main()
{
Student stud;
Professional prof;
Person *pIndividual1 = &stud;
Person *pIndividual2 = &prof;
stud.getData();
prof.getData();
stud.display();
prof.display();
pIndividual1->getData();
pIndividual2->getData();
pIndividual1->display();
pIndividual2->display();
return 0;
}