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.Runtime Input :
1200
Raja
12500
1200
1500
1800
#include<iostream>
using namespace std;
class employee{
public:
int emp_no;
char emp_name[25];
void get(){
cout<<"enter employee number";
cin>>emp_no;
cout<<"enter employee name";
cin>>emp_name;
}
};
class salary : public employee{
float basic_pay,HRA,DA,PF,net_pay;
public:
void get1(){
cout<<"enter the basic pay";
cin>>basic_pay;
cout<<"enter HRA";
cin>>HRA;
cout<<"Enter DA";
cin>>DA;
cout<<"Enter PF";
cin>>PF;
}
void total_payment(){
net_pay=basic_pay+HRA+DA-PF;
}
void display(){
cout<<emp_no<<"\t"<<emp_name<<"\t"<<basic_pay<<"\t"<<HRA<<"\t"<<DA<<"\t"<<PF<<"\t"<<net_pay<<"\n";
}
};
int main(){
int n;
salary s[10];
cout<<"enter total no. of employee";
cin>>n;
for(int i=0;i<n;i++){
s[i].get();
s[i].get1();
s[i].total_payment();
}
cout<<"emp_no \t emp_name \t Basis pay \t HRA \t DA \t PF \t net_payment \n";
for(int i=0;i<n;i++){
s[i].display();
}
return 0;
}
Comments
Leave a comment