Answer to Question #329696 in C++ for Abishek

Question #329696

Write a program to calculate gross and net pay of employee from basic salary. Create employee class which consists of employee name, emp_id, and basic salary as its data members. Use parameterized constructor in the derived class to initialize data members of the base class and calculate gross and net pay of the employee in the derived class.

1
Expert's answer
2022-04-17T07:41:10-0400
#include<iostream>
#include<string>

using namespace std;

class Employee
{
	string name;
	int emp_id;
	double basic_sal;
protected:
	Employee(string _name,int _emp_id, double _basic_sal)
	:name(_name), emp_id(_emp_id), basic_sal(_basic_sal){}
	void DisplayEmployee()
	{
		cout << "\nName of employee is " << name
			<< "\nEmployee ID of employee is " << emp_id
			<< "\nBasic salary of employee is " << basic_sal;
	}
	double GetSalary() { return basic_sal; }
};


class Calculate:public Employee
{
	double gross_pay;
	double net_pay;
public:
	Calculate(string _name,	int _emp_id, double _basic_sal)
	:gross_pay(0), net_pay(0),Employee(_name, _emp_id, _basic_sal){}
	void CalculateGross()
	{
		float suppl;
		cout << "Please, enter salary supplements (from 1 to 40): ";
		cin >> suppl;
		gross_pay = suppl*GetSalary()+GetSalary();
	}
	void CalculateNet()
	{
		float taxes;
		cout << "Please, enter share of taxes (from 1 to 40): ";
		cin >> taxes;
		net_pay = gross_pay-(gross_pay*taxes / 100);
	}
	void Display()
	{
		DisplayEmployee();
		cout << "\nGross salary is " << gross_pay
			<< "\nNet pay is " << net_pay;
	}
};

int main()
{
	Calculate a("Jack", 1234, 3000);
	a.CalculateGross();
	a.CalculateNet();
	a.Display();
}







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