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.
#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();
}
}
Comments
Leave a comment