Idea Solution CS304

Sponsored Links


Code:
#include<iostream.h>
#include<conio.c>
//Employee class definition
class Employee
{
public:
Employee(){}
//pure virtual method
virtual void DisplayName()=0;
};
//Salaried Employee class definition
class SalariedEmployee:public Employee
{
public:
SalariedEmployee(){}
//overriden DisplayName
virtual void DisplayName(){
cout<<"This is Salaried Employee"<<endl;}
};
//Commission Employee class definition
class CommissionEmployee:public Employee
{
public:
CommissionEmployee(){}
//overriden displayName
virtual void DisplayName(){
cout<<"This is Commission Employee"<<endl;}
};
void main()
{ //pointer to Employee declaration
Employee *obj;
//polymorphically call of DisplayName of Salaried Employee
obj = new SalariedEmployee();
obj->DisplayName();
//Polymorphically call of DisplayName of Commission Employee
obj= new CommissionEmployee();
obj->DisplayName();
getch();
}