Reusability using inheritance
Design a pay roll system to find the employee total salary using single inheritance. The base class employee consisting of data members such as emp_number and emp_name. The derived class salary consisting of data members such as Basic_pay, HRA, DA, PF, Net_pay.
run time input
1200
raja
12500
1200
1500
1800
output should
1200
raja
12500
1200
1500
1800
17000
#include<iostream>
using namespace std;
class employee
{
public:
int e_id;
char name[20],designation[20];
void get()
{
cout<<"Enter employee ID:";
cin>>e_id;
cout<<"Name of Employee:";
cin>>name;
cout<<"Degination:";
cin>>designation;
}
};
class salaryCalc:public employee
{
float basicPay,hra,da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>basicPay;
cout<<"Enter the Human Resource Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the provisional Fund:";
cin>>pf;
}
void calculate()
{
np=basicPay+hra+da-pf;
}
void display()
{
cout<<e_id<<"\t"<<name<<"\t"<<designation<<"\t"<<basicPay<<"\t"<<hra<<
"\t"<<da<<"\t"<<pf<<"\t"<<np<<"\n";
}
};
int main()
{
int i,n;
char ch;
salaryCalc s[10];
cout<<"Total number of employee in the organization:";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\e_id \t Name\t Des \t BPay \t hra \t da \t pf \t np \n";
for(i=0;i<n;i++)
{
s[i].display();
}
return 0;}
Comments
Leave a comment