) Write a program that uses a class Employee to display Employee details. The class should
include the following members.
Data members :Empno, Empnname, basic pay, house allowance, medical allowance.
Member Function:to read employee details,to calculate gross salary and net salary.
Gross salary=basic+house all + med allowance
Net salary=gross salary – tax
#include <iostream>
using namespace std;
class Employee{
int Empno;
char Empnname[30];
float basicPay;
float houseAllowance;
float medicalAllowance;
float grossSalary;
float netSalary;
public:
Employee(){
readDetails();
}
void readDetails(){
cout<<"Enter employee no: ";
cin>>Empno;
cout<<"Enter employee name: ";
cin.get();
cin.getline(Empnname, 30);
cout<<"Enter basic Pay: ";
cin>>basicPay;
cout<<"Enter house allowance: ";
cin>>houseAllowance;
cout<<"Enter medical allowance: ";
cin>>medicalAllowance;
}
float calculateGrossSalary(){
grossSalary = basicPay + houseAllowance + medicalAllowance;
return grossSalary;
}
float calculateNetSalary(){
float tax = 0.16 * basicPay;
netSalary = grossSalary - tax;
return netSalary;
}
};
int main(){
Employee employee;
cout<<"Gross Salary: "<<employee.calculateGrossSalary()<<endl;
cout<<"Net Salary: "<<employee.calculateNetSalary()<<endl;
return 0;
}
Comments
Leave a comment