Answer to Question #200367 in C++ for Ahmed Ali

Question #200367

Write a program using class ‘employee’ to compute the allowances, net pays and print on the screen. The class also should have the following data members: - Emp_no, basic_pay, house_rent, medical_allow, conveyance_allownce and net pay. The class should have the following member functions:-  One member function ‘inputdata’ to get values in temp_no and basic_pay.  One member function ‘compute_pay’ to compute allowances and net pay. The allowances and net pay is calculated as: o ‘house_rent’ is 45% of basic pay. o ‘Medical_allow’ is 15% of basic pay. o ‘conveyance_allownce’ is 10% of basic pay. o ‘net_pay’ is calculated as:  net_pay=basic_pay+house_rent+medical_allown  +conveyance_allownce  One member function ‘print_pay’ to print the pay.  


1
Expert's answer
2021-05-30T07:22:55-0400
#include<iostream>
#include<bits/stdc++.h>
using namespace std;


class employee{
	public:
		int Emp_no;
		int basic_pay;
		int house_rent;
		int medical_allow;
		int conveyance_allownce;
		int net_pay;
		
		void input()
		{
			cout<<"Enter Employee number : ";
			cin>>Emp_no;
			cout<<"Enter Basic pay : ";
			cin>>basic_pay;
		}
		
		void compute_pay()
		{
			house_rent = 0.45*basic_pay;
			medical_allow = 0.15*basic_pay;
			conveyance_allownce = 0.10*basic_pay;
			net_pay = basic_pay + house_rent + medical_allow + conveyance_allownce;
		}
		
		void print_pay()
		{
			cout<<setw(8)<<Emp_no<<setw(18)<<net_pay<<endl;
		}
			
};


int main()
{
	cout<<"Enter number of Employees : ";
	int n;
	cin>>n;
	employee e[n];
	cout<<endl;
	for(int i=0; i<n; i++)
	{
		cout<<"Enter details of Employee"<<endl;
		e[i].input();
		e[i].compute_pay();
		cout<<endl;
	}
	
	cout<<"Employee Number"<<setw(30)<<"The net pay of Employee"<<endl;
	cout<<"-----------------------------------------------------"<<endl;
	for(int i=0; i<n; i++)
	{
		e[i].print_pay();
	}
	
}

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