Write a base class named Employee and derive classes Male employee and Female Employee from it. Every employee has an id, name and a scale of salary. Make a function ComputePay (in hours) to compute the weekly payment of every employee. A male employee is paid on the number of days and hours he works. The female employee gets paid the wages for 40 hours a week, no matter what the actual hours are. Test this program to calculate the pay of employee.
CODING:
#include<iostream.h>
#include<conio.h>
class female;
class male;
class employee
{
public:
int id,salary,hours,day;
char name[10];
};
class male:public employee
{
public:
void setdata()
{
cout<<"Male Employee ID :";
cin>>id;
cout<<"Male Employee Name :";
cin>>name;
cout<<"How many Days to work:";
cin>>day;
cout<<"How many Hours to work:";
cin>>hours;
}
void compute_pay()
{
salary=(hours*day)*100;
}
void display()
{
cout<<"About of "<<name<<"..";
cout<<"\nEmployee ID :"<<id;
cout<<"\nEmployee Name :"<<name;
cout<<"\nEmployee Salary:"<<salary;
}
};
class female:public employee
{
public:
void setdata()
{
cout<<"\n\nFemale Employee ID :";
cin>>id;
cout<<"Female Employee Name :";
cin>>name;
cout<<"How many Days to work:";
cin>>day;
cout<<"How many Hours to work:";
cin>>hours;
}
void compute_pay()
{
salary=(hours*day)*40;
}
void display()
{
cout<<"About of "<<name<<"..";
cout<<"\nEmployee ID :"<<id;
cout<<"\nEmployee Name :"<<name;
cout<<"\nEmployee Salary:"<<salary;
}
};
void main()
{
male obj1;
female obj2;
clrscr();
obj1.setdata();
obj1.compute_pay();
obj1.display();
obj2.setdata();
obj2.compute_pay();
obj2.display();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class female;
class male;
class employee
{
public:
int id,salary,hours,day;
char name[10];
};
class male:public employee
{
public:
void setdata()
{
cout<<"Male Employee ID :";
cin>>id;
cout<<"Male Employee Name :";
cin>>name;
cout<<"How many Days to work:";
cin>>day;
cout<<"How many Hours to work:";
cin>>hours;
}
void compute_pay()
{
salary=(hours*day)*100;
}
void display()
{
cout<<"About of "<<name<<"..";
cout<<"\nEmployee ID :"<<id;
cout<<"\nEmployee Name :"<<name;
cout<<"\nEmployee Salary:"<<salary;
}
};
class female:public employee
{
public:
void setdata()
{
cout<<"\n\nFemale Employee ID :";
cin>>id;
cout<<"Female Employee Name :";
cin>>name;
cout<<"How many Days to work:";
cin>>day;
cout<<"How many Hours to work:";
cin>>hours;
}
void compute_pay()
{
salary=(hours*day)*40;
}
void display()
{
cout<<"About of "<<name<<"..";
cout<<"\nEmployee ID :"<<id;
cout<<"\nEmployee Name :"<<name;
cout<<"\nEmployee Salary:"<<salary;
}
};
void main()
{
male obj1;
female obj2;
clrscr();
obj1.setdata();
obj1.compute_pay();
obj1.display();
obj2.setdata();
obj2.compute_pay();
obj2.display();
getch();
}
Comments
Post a Comment