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.
#include <iostream>
#include <string>
using namespace std;
class Employee Â
{
//The employee base class consisting of member variables such as name and empid
private:
int empid;
string emp_name;
public:
//Constructor
Employee(int empid,string emp_name){
this->empid=empid;
this->emp_name=emp_name;
}
//display employee information
virtual void display(){
cout<<"Employee id: "<<empid<<"\n";
cout<<"Employee name: "<<emp_name<<"\n";
}
};
class SalaryEmployee: public Employee{
private:
//The derived class salary consisting of data members such as Basic_pay, HRA, DA, PF, Net_pay.
float Basic_pay;
float HRA;
float DA;Â
float PF;
float Net_pay;
public:
//Constructor with arguments
SalaryEmployee(int empid,string emp_name,float Basic_pay,float HRA,float DA,float PF):Employee(empid,emp_name){
this->Basic_pay=Basic_pay;
this->HRA=HRA;
this->DA=DA;
this->PF=PF;
//calculate net pay
this->Net_pay=Basic_pay+HRA+DA-PF;
}
//display salary Employee information
void display(){
Employee::display();
cout<<"Employee basic pay: "<<Basic_pay<<"\n";
cout<<"Employee HRA: "<<HRA<<"\n";
cout<<"Employee DA: "<<DA<<"\n";
cout<<"Employee PF: "<<PF<<"\n";
cout<<"Employee net pay: "<<Net_pay<<"\n\n";
}
};
int main(){
SalaryEmployee salaryEmployeeMike(456651,"Mike",2300,230,120,90);
SalaryEmployee salaryEmployeeMary(134335,"Mary",2500,200,100,50);
SalaryEmployee salaryEmployeeJohn(487466,"John",1500,100,150,120);
salaryEmployeeMike.display();
salaryEmployeeMary.display();
salaryEmployeeJohn.display();
return 0;
}
Comments
Leave a comment