# 1 – Best C++ program to calculate employee salary

## C++ program to calculate employee salary

C++ program to calculate employee salary : Write a program that calculates weekly payments. The program will ask for users full name, ID number, hours worked and rate per hour.
Hourly worker’s gross pay is basically his/her work hours of that week multiplied by his/her regular hourly pay rate.

However, after the first 40 work hours of week, each additional work hours is paid at an overtime rate that is 1.5 times the regular hour rate.
Use a loop to allow user to enter multiple employees.

### C++ program to calculate salary of an employee

`#include <iostream> using namespace std;class Employee {     string e_name, e_id;    double e_hourwork, e_rateperhour, netsal, grossPay, otrate;     public:    void getEmployee(string &ename, string &eid, double &hourWork, double &ratePerHour)    {        e_name = ename;        e_id = eid;        e_hourwork = hourWork;        e_rateperhour = ratePerHour;    }    void calculateGrossPay()    {        double ot, sal;        if(e_hourwork <= 40)        {            grossPay = e_hourwork*e_rateperhour;        }        else        {            sal = 40 * e_rateperhour;            ot = e_hourwork - 40;            otrate = e_rateperhour * 1.5;            grossPay = ((ot * otrate)+sal);        }    }    void calculateNetPay(int taxRate)    {        double tax = ((double)taxRate/100)*grossPay;        netsal = grossPay-tax;    }    void printEmolyeePayment()    {        cout << "nn Name of Employee : "<<e_name<<"n Employee ID : "<<e_id<<"n Net Pay of Empoloyee : "<<netsal;    }};int main(){    string ename, eid;    double hourwork, rateperhour;    char flag='y';    double grosspay, netpay;    double tax = 5;    int i=0;    Employee e[10];    while(flag=='y')    {        cout << "nEnter employee detailsn";        cout << "Name Of Employee : ";        cin >> ename;        cout << "ID Of Employee : ";        cin >> eid;        cout << "Work Hour Of Employee : ";        cin >> hourwork;        cout << "Rate Per Hour Of Employee : ";        cin >> rateperhour;        e[i].getEmployee(ename, eid, hourwork, rateperhour);        i++;        cout<<"Do you want to enter details of another employee ? y/n :";        cin>>flag;    }    for(int j=0; j<i; j++)    {         e[j].calculateGrossPay();        e[j].calculateNetPay(tax);        e[j].printEmolyeePayment();    }    return 0;}`

### Output

Enter employee details
Name Of Employee : Rajesh
ID Of Employee : 101
Work Hour Of Employee : 50
Rate Per Hour Of Employee : 100
Do you want to enter details of another employee ? y/n :y

Enter employee details
Name Of Employee : Suresh
ID Of Employee : 102
Work Hour Of Employee : 40
Rate Per Hour Of Employee : 150
Do you want to enter details of another employee ? y/n :y

Enter employee details
Name Of Employee : Naresh
ID Of Employee : 103
Work Hour Of Employee : 60
Rate Per Hour Of Employee : 80
Do you want to enter details of another employee ? y/n :n

Name of Employee : Rajesh
Employee ID : 101
Net Pay of Empoloyee : 5225

Name of Employee : Suresh
Employee ID : 102
Net Pay of Empoloyee : 5700

Name of Employee : Naresh
Employee ID : 103
Net Pay of Empoloyee : 5320

### PRACTICALS/PRACTICE PROGRAM IN C++

 1 – Best C++ program to calculate employee salary More practical coming soon.

We are aiming to explain all concepts of C++ in easiest terms as possible.
ITVoyagers
Author