Take this same class person and class student and create a test program that use
ID: 3561612 • Letter: T
Question
Take this same class person and class student and create a test program that uses a polymorphic pointer pIndividual. Be careful to add the virtual keyword only where required.
#include "stdafx.h"
#include
#include
using namespace std;
//Create a class person, which has a name, address, city, state, zip and phone number, with all the proper constructors, and access functions.
class person
{
private:
string name;
string address;
string city;
string state;
string zip;
string phoneNumber;
public:
person(string pName, string pAddress, string pCity, string pState, string pZip, string pPhoneNumber)
{
name = pName;
address = pAddress;
city = pCity;
state = pState;
zip = pZip;
phoneNumber = pPhoneNumber;
}
string getName() { return name; }
string getAddress() { return address; }
string getCity() { return city; }
string getState() { return state; }
string getZip() { return zip; }
string getphoneNumber() { return phoneNumber; }
};
//Create a class student, which inherits from person, and has additionally grade, course, and GPA, with all proper constructors and access functions.
class student : public person
{
private:
char grade;
string course;
double GPA;
public:
student(string pName, string pAddress, string pCity, string pState, string pZip, string pPhoneNumber, char pGrade, string pCourse, double pGPA) :person(pName, pAddress, pCity, pState, pZip, pPhoneNumber)
{
grade = pGrade;
course = pCourse;
GPA = pGPA;
}
char getGrade() { return grade; }
string getCourse() { return course; }
double getGPA() { return GPA; }
};
//Write a test program to prove that your inheritance is working.
int main()
{
student Data("Ryan", "123 Fake St", "Chicago", "IL", "60616", "847-262-4541", 'C', "Prog2", 2.0);
cout << "Student name is " << Data.getName() << endl;
cout << "Student address is " << Data.getAddress() << endl;
cout << "Student city is " << Data.getCity() << endl;
cout << "Student state is " << Data.getState() << endl;
cout << "Student zip is " << Data.getZip() << endl;
cout << "Student phone number is " << Data.getphoneNumber() << endl;
cout << "Student grade is " << Data.getGrade() << endl;
cout << "Student course is " << Data.getCourse() << endl;
cout << "Student GPA is " << Data.getGPA() << endl;
system("pause");
return 0;
}
Explanation / Answer
#include #include using namespace std; class Person { public: string m_Name, m_Address, m_City, m_State; int m_Zip, m_Phone_Number; void virtual list_stats(); }; void Person::list_stats() { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.