in the Module 06 Programming Assignment (Inheritance Proved) you created a progr
ID: 3766429 • 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 "stdafx.h"
#include<string>
using namespace std;
class person
{
private:
string name;
string address;
string city;
string state;
string zip;
string phone_no;
public:
person(string n, string a,string c,string s,string z, string p)
{
name=n;
address=a;
city=c;
state=s;
zip=z;
phone_no=p;
}
string getName()
{
return name;
}
string getAddress()
{
return address;
}
string getCity()
{
return city;
}
string getState()
{
return state;
}
string getZip()
{
return zip;
}
string getPhone_no()
{
return phone_no;
}
void display()
{
cout<<"shows the deatils of person"<<endl;
}
};
class student : public person
{
private:
char grade;
string course;
double GPA;
public:
student(string n, string a,string c,string s,string z, string p,char g,string co, double G):person(n,a,c,s,z,p)
{
grade=g;
course=co;
GPA=G;
}
char getGrade()
{
return grade;
}
string getCourse()
{
return course;
}
double getGPA()
{
return GPA;
}
void display()
{
cout<<"student credentials: "<<"grade:"<<grade<<" course:"<<course<<" GPA:"<<GPA<<endl;
}
};
class professional : public person
{
private:
string department;
string designation;
int experiance;
public:
professional(string n, string a,string c,string s,string z, string p, string de, string d,int e):person(n,a,c,s,z,p)
{
department=d;
designation=de;
experiance=e;
}
string getDeparment()
{
return department;
}
string getDesignation()
{
return designation;
}
int getExperiance()
{
return experiance;
}
void display()
{
cout<<"professional deatils: "<<" department:"<<department<<" designation:"<<designation<<" experiance:"<<experiance<<endl;
}
};
int main()
{
student s("James","Wood Dale","Batavia","New York","60510","123456","A","Computer Science",9.5);
professional pre("Suresh","India","Vizag","Andhra Pradesh","530001","12345623","Computer Science","professor",5);
person *p;
p->display();
p=&s;
p->display();
p=⪯
p->display();
cout<< "student name:"<<s.getName() << endl;
cout<< "student address:"<<s.getAddress() << endl;
cout<< "student city:"<<s.getCity() << endl;
cout<< "student state:"<<s.getState() << endl;
cout<< "student zip:"<<s.getZip() << endl;
cout<< "student phone_no:"<<s.getPhone_no() << endl;
cout<< "student grade:"<<s.getGrade() << endl;
cout<< "student course:"<<s.getCourse() << endl;
cout<< "student GPA:"<<s.getGPA() << endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.