Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write the simplist c++ code for the following: Write a complete C++ progr

ID: 3681399 • Letter: P

Question

Please write the simplist c++ code for the following:

Write a complete C++ program, including at least 3 good comments, to do the following:

Your program will compute the pay of a group of employee. It will read the data from a text file. The file will contain (on each line) name rate hours.

You are to read the name into a String variable (it’s just a last name). If you have not read to the EOF you are to now read the rate and the hours worked. You should now print the name and the hours worked and the pay rate. You should now call a function called calcpay which is passed two parameters – the rate and the hours. It should return the total pay, which is then printed by the main program.

It should calculate the pay according to regular hours * rate + overtime * rate * 1.5. Overtime consists of any hours worked past 40 hours. You should then attempt to read the next employee name and continue as above (Use a structured read loop as in class.) Make sure you test with at least 5 employees, some with and some without overtime.

the end of the program should output print the number of employees, and the total payroll of the group of employees

Explanation / Answer


#include <fstream>
#include<iostream>
using namespace std;

double calcpay(double rates, double hours);

int main()
{
ifstream fin;
char fileName[20];
  
// getting filename from user
cout<<"Enter a file name: ";
cin>>fileName;
  
// opening a file
fin.open (fileName);

   int count = 0; // count number of totla employee
   double totalPay = 0; // total payroll
  
string name;
double hours;
double rates;
// reading name, rates, hours of a employee in each iteration
while (fin >> name >> rates >> hours)
{
       count++;
       cout<<"Name: "<<name<<", Rates: "<<rates<<", and Hours: "<<hours<<endl;
       // calling calcpay function to get pay of current employee
       double pay = calcpay(rates, hours);
      
       cout<<"Pay : "<<pay<<endl<<endl;
      
       // adding pay of current empoyee into total
      
       totalPay = totalPay + pay;
}
  
cout<<"Total number of Employee: "<<count<<endl;
cout<<"TOtal payroll: "<<totalPay<<endl;
  
return 0;
  
}

double calcpay(double rates, double hours){
   double pay = 0;
  
   if(hours > 40){// overtime case
       pay = (40*rates) + ((hours-40)*rates*1.5); // regular hours + overtime
   }
   else{
       pay = hours*rates; // no overtime
   }
   return pay;
}

/*

Output:

payroll.txt:

Alex 30 45
Bob 34.5 38
Elur 30.5 46
Pravesh 40.0 35
Mukesh 36 50

Enter a file name: payroll.txt
Name: Alex, Rates: 30, and Hours: 45
Pay : 1425

Name: Bob, Rates: 34.5, and Hours: 38
Pay : 1311

Name: Elur, Rates: 30.5, and Hours: 46
Pay : 1494.5

Name: Pravesh, Rates: 40, and Hours: 35
Pay : 1400

Name: Mukesh, Rates: 36, and Hours: 50
Pay : 1980

Total number of Employee: 5
TOtal payroll: 7610.5

*/