Answer to Question #270457 in C++ for Kelvin

Question #270457

) 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


1
Expert's answer
2021-11-23T05:28:41-0500
#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;
}

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