Answer to Question #179383 in C++ for Ajith

Question #179383

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.


1
Expert's answer
2021-04-11T02:33:37-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS