Answer to Question #173957 in C++ for Ajith

Question #173957

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-03-23T04:55:42-0400
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::endl;
class Emploee
{

protected:
	int emp_number{0};
	string emp_name{ "Empty" };
public:
	Emploee() {}
	Emploee(int a, string b) :
		emp_number(a), emp_name(b)
	{}
	void set_number(int number) {
		emp_number = number;
	}
	int get_number() {
		return emp_number;
	}
	void set_name(string name) {
		emp_name = name;
	}
	string get_name() {
		return emp_name;
	}
	void display_emp() {
		cout << "Emp number " << get_number()<<endl;
		cout << "Emp name " << get_name() << endl;


	}
};
class Sallary :protected Emploee
{
public:
	Sallary() {}
	Sallary(int number,string name,double basic,
		double hra,double da,double pf):
		Emploee(number,name),
		basic_pay(basic),hra(hra),da(da),pf(pf)
	{}
	


	void display() {
		display_emp();
		cout << "Sallary net =" <<total_pay() << endl;
	}
	void set_pay(double pay) {
		basic_pay = pay;
	}
	void set_hra(double hra) {
		hra = hra;
	}
	void set_da(double da) {
		da = da;
	}
	void set_pf(double da) {
		pf = pf;
	}
	
	
private:
	double basic_pay{ 0 };
	double hra{ 0 };
	double da{ 0 };
	double pf{ 0 };
	double net_pay{ 0 };
	double total_pay()
	{
		net_pay = basic_pay + hra + da - pf;
		return net_pay; 
	}
	
};
int main()
{
	// example
	Sallary elem(12,"Bob",2000, 150, 100, 78);
	elem.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