C++ Need to add this to my code below. Add a class Professional that inherits fr
ID: 667562 • Letter: C
Question
C++ Need to add this to my code below.
Add a class Professional that inherits from Person and overrides its display() method. Now take all 3 classes and use Polymorphism on the display() method. In main(), use polymorphic pointer variable pIndividual of type Person to call the corresponding display()method of all the three classes.
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Person
{
private:
string name,state,address,city,zip,phone;
public:
//Default constructor
Person()
{
name = "Joe";
address = "13 North St";
city = "New York";
state="NY";
zip = "33333";
phone = "xxx xxx xxxx";
}
void display()
{
cout<<"Name: "<<name<<" "<<address<<" "
<<"City: "<<city<<" "<<"State: "<<state<<" "
<<"Zip: "<<zip<<endl;
}
};
class Student:public Person
{
private:
char grade;
string course;
float GPA;
public:
//Default constructor
Student()
{
grade = 'A';
course = "Programming II";
GPA = 4.0;
}
void display()
{
Person::display();
cout<<"Grade: "<<grade<<endl
<<"Course: "<<course<<endl
<<"GPA: "<<GPA<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Person a;
a.display();
Student b;
b.display();
system("PAUSE");
return 0;
}
Explanation / Answer
main.cpp
Course.cpp
course.h
Person.cpp
Person.h
Student.cpp
Student.h
display.txt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.