(Pure Virtual Function) Write the above program by modifying by making display() as pure virtual
function.
#include<iostream>
#include<string>
using namespace std;
class Person
{
int ID;
string name;
public:
Person(int _ID, string _name):ID(_ID),name(_name){}
virtual void Display() = 0;
int GetID() { return ID;}
string GetName() { return name;}
};
class Worker:public Person
{
double salary;
string prof;
public:
Worker(int _ID, string _name, double _salary,string _prof)
:Person(_ID,_name),salary(_salary),prof(_prof){}
virtual void Display()
{
cout << "Worker's name is\t" << GetName()
<< "\nWorker's ID is\t\t" << GetID()
<< "\nWorker's profession is\t" << prof
<< "\nWorker's salary is\t" << salary;
}
};
int main()
{
Worker worker(47845, "Peter", 450000, "Programmer");
Person* person;
person = &worker;
person->Display();
int k;
cin>>k;
}
Comments
Leave a comment