Write a C program to process a payroll for a small company C

Write a C ++program to process a payroll for a small company. Calculate gross pay including the possibility of overtime. Calculate payroll tax depending on the employee code and state code. Display the gross salary, tax, and net salary for each employee. Overtime is paid at the rate of 150% of hourly wages for every hour over 40. Employees with Code B pay no taxes. Employees with Code A pay 7% if their State Code is Y; Code A employees with State Code J pay only 4.5% taxes. Assume the user does not make any error when inputting data. Allow inputs for multiple employees. Output summary information as shown in the sample output below when you quit, that is, when asked if you want to process another employee, you type in an ‘n’. Show results for at least 3 employees.

Solution

Please follow the cod eand comments for description :

CODE :

#include <iostream> // required header files
#include <string>
#include <iomanip>

using namespace std;

int main() // driver method
{
   cout << \"This program calculates the net pay for the each employee and the gross pay.\" << endl; // prompt about the code
   cout << \"\ At each prompt, enter the requested data.\" << endl;
   double payRate, workedHrs, regPay, otPay, grossPay, tx, netPay, totGrossPay = 0, totNetPay = 0, totTax = 0, totalPay = 0; // local varaibles
   int empCount = 0;
   char empCode, stateCode, choice;
  
   while(true) { // iterate till the user desire to exit
      
       empCount++; // count of the employess gets incremented
       cout << \"\ Enter the pay rate : \"; // prompt to enter the pay rate
       cin >> payRate; // get the pay rate
       cout << \"Enter the number of hours worked : \"; // prompt to enter the hours
       cin >> workedHrs; // get the data
       cout << \"Enter the Employee Code (A or B) : \"; // prompt to enter the emp code
       cin >> empCode; // get the data
       cout << \"Enter the state code (Y or J) : \"; // prompt to enter the state code
       cin >> stateCode; // get the data
      
       if(workedHrs <= 40) { // check for the worked hours
           regPay = payRate * workedHrs; // calculate the amount
           otPay = 0;
       } else {
           regPay = payRate * 40;
           payRate = payRate * 1.5;
           otPay = payRate * (workedHrs - 40); // calculate the Overtime
       }
      
       cout.precision(2); // set the precision of the console to 2 digits
       cout << \"\ Regular Pay : \" << setw(8) << fixed << regPay << endl; // print the data
       cout << \"Overtime Pay : \" << setw(7) << fixed << otPay << endl; // print the data
      
       grossPay = regPay + otPay; // calculate the gross pay
       cout << \"Gross Pay : \" << setw(10) << fixed << grossPay << endl; // print the data
       totalPay = regPay + otPay; // calculate the total pay
       totGrossPay = totGrossPay + grossPay; // calculate the total gross pay
      
       if(empCode == \'A\') { // claculate the tax payable
           if(stateCode == \'Y\') {
               tx = totalPay * 0.07;
           } else if (stateCode == \'J\') {
               tx = totalPay * 0.045;
           }
       } else if(empCode == \'B\') {
           tx = 0;
       }
       cout << \"Tax : \" << setw(16) << fixed << tx << endl; // print the data
       totTax = totTax + tx;
       cout << \"--------------------------------\" << endl;
       netPay = grossPay - tx; // calculate the net pay
       totNetPay = totNetPay + netPay;
       cout << \"Net Pay : \" << setw(11) << fixed << netPay << endl; // print the data
       cout << \"\ Do you want to process another employee (y or n) : \"; // get the choice for the next user to enter
       cin >> choice; // get the data
      
       if(choice == \'n\') { // check for the choice
           break;
       } else {
           continue;
       }
   }
  
   cout << \"\ Total Number of Employees Processed : \" << empCount << endl; // print the resultant data
   cout << \"Total Gross Pay : \" << setw(8) << fixed << totGrossPay << endl;
   cout << \"Total Tax : \" << setw(14) << fixed << totTax << endl;
   cout << \"Total Net Pay : \" << setw(10) << fixed << totNetPay << endl;
  
   return 0;
}


OUTPUT :

This program calculates the net pay for the each employee and the gross pay.

At each prompt, enter the requested data.

Enter the pay rate : 7.25
Enter the number of hours worked : 47
Enter the Employee Code (A or B) : A
Enter the state code (Y or J) : Y

Regular Pay : 290.00
Overtime Pay : 76.12
Gross Pay : 366.12
Tax : 25.63
--------------------------------
Net Pay : 340.50

Do you want to process another employee (y or n) : y

Enter the pay rate : 8.5
Enter the number of hours worked : 30
Enter the Employee Code (A or B) : A
Enter the state code (Y or J) : J

Regular Pay : 255.00
Overtime Pay : 0.00
Gross Pay : 255.00
Tax : 11.47
--------------------------------
Net Pay : 243.53

Do you want to process another employee (y or n) : y

Enter the pay rate : 6
Enter the number of hours worked : 50
Enter the Employee Code (A or B) : B
Enter the state code (Y or J) : Y

Regular Pay : 240.00
Overtime Pay : 90.00
Gross Pay : 330.00
Tax : 0.00
--------------------------------
Net Pay : 330.00

Do you want to process another employee (y or n) : n

Total Number of Employees Processed : 3
Total Gross Pay : 951.12
Total Tax : 37.10
Total Net Pay : 914.02


Hope this is helpful.

Write a C ++program to process a payroll for a small company. Calculate gross pay including the possibility of overtime. Calculate payroll tax depending on the
Write a C ++program to process a payroll for a small company. Calculate gross pay including the possibility of overtime. Calculate payroll tax depending on the
Write a C ++program to process a payroll for a small company. Calculate gross pay including the possibility of overtime. Calculate payroll tax depending on the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site