please read the above assignment and use this code to create the polymophic poin
ID: 3548675 • Letter: P
Question
please read the above assignment and use this code to create the polymophic pointer. Answer with comments please, thank you
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
string name;
string address;
string city;
string state;
int PhoneNumber;
void Setter();
virtual void Getter()
{
cout <<"Name :" << name << endl;
cout <<"Address :" << address << endl;
cout <<"City :" << city << endl;
cout <<"State :" << state << endl;
}
};
class Student:public Person
{
public:
int Grade;
string Course;
float GPA;
void Setter(string name,string address,string city,string state,int PhoneNumber, int Grade,string Course,float GPA)
{
this->name = name;
this->address = address;
this->city = city;
this->state = state;
this->PhoneNumber = PhoneNumber;
this->Grade = Grade;
this->Course = Course;
this->GPA = GPA;
}
void Getter()
{
cout <<"Name :" << name << endl;
cout <<"Address :" << address << endl;
cout <<"City :" << city << endl;
cout <<"State :" << state << endl;
cout << "Phone Number :" << PhoneNumber << endl;
cout <<"Grade :" << Grade <<endl;
cout << "Course :" << Course <<endl;
cout <<"GPA :" << GPA << endl;
}
};
int main()
{
//CREATE STUDENT OBJECT.
Student SO;
SO.Setter("bobdole","203 windchest ave","Houston","TX",24983534,11,"Math",3.45);
// declare polymorphic pointer pIndividual
Person* pIndividual = NULL;
// let it point to student object.
pIndividual = &SO;
// call getter on top of pIndividual pointer.
pIndividual->Getter();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.