Answer to Question #269169 in C++ for kool

Question #269169

(Pure Virtual Function) Write the above program by modifying by making display() as pure virtual

function.


1
Expert's answer
2021-11-21T04:58:00-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS