Print Friendly and PDF
#include <iostream.h>
#include <conio.h>
using namespace std;
class employee

{
private:
char name[40];
int empno;
public:
employee();
virtual void calculate_sal()=0;
friend ostream &operator <<(ostream &os,const employee &e);
friend istream &operator >>(istream &in,employee &e);
~employee();
};
employee::employee()
{
*name=NULL;
empno=0;
}
ostream &operator <<(ostream &os,const employee &e)
{
os<<'('<<e.name<<','<<e.empno<<')';
return os;
}
istream &operator >>(istream &in,employee &e)
{
in>>e.name;
in>>e.empno;
return in;
}
employee::~employee()
{
cout<<"distructor called"<<endl;
}
class permanent:public employee

{
public:
virtual void calculate_sal()
{
permanent p;
cout<<"enter the permanent employee name & employee no:"<<endl;
cin>>p;
int month,total_sal;
cout<<"enter the no of months that permanent employee has worked "<<endl;
cin>>month;
total_sal=month*25000;
cout<<"permanent employee salary is "<<total_sal<<endl;
}
};
class dailybase:public employee

{
public:
virtual void calculate_sal()
{
dailybase d;
cout<<"enter the daily base employee name & emp number: "<<endl;
cin>>d;
int day,total_sal;
cout<<"enter the number of days that the daily base employee has worked "<<endl;
cin>>day;
total_sal=day*600;
cout<<"daily base employee salary is "<<total_sal<<endl;
}
};
class hourlybase:public employee

{
public:
virtual void calculate_sal()
{
hourlybase h;
cout<<"enter the hourly base employee name & emp no:"<<endl;
cin>>h;
int hour,total_sal;
cout<<"enter the number of hours that the hourly base employee has worked "<<endl;
cin>>hour;
total_sal=hour*200;
cout<<"hourly base employee salary is"<<total_sal<<endl;
}
};
void salary(employee* sal[],int size)
{
for(int i=0;i<size;i++)
{
sal[i]->calculate_sal();
}
}
int main()
{
int size=3;
employee* sal[size];
sal[0]=new permanent();
sal[1]=new dailybase();
sal[2]=new hourlybase();
salary(sal,size);
getch();
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: