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

anyone can help? You may only use Visual Studio (including the MSDN online help

ID: 3576148 • Letter: A

Question

anyone can help?

You may only use Visual Studio (including the MSDN online help system) and your course textbook as resources lo You must submit your solution at the end of your lab session. Late exam solutions will not be accepted! To submit your solution, you will need to .zip up your Visual Studio project space and place it on your TAs USB flash will then need to delete all copies your project from your computer! If you are caught accessing the web or any other outside source materials during the lab period, if you do not sheet (with your name on it back to your instructor at the end of the lab period, or if you are caught collaboratin another student (including someone in another lab section), you will receive an automatic 0 and fail the course. I hereby understand and agree to abide by the exam rules. Printed Name Signature: Programming Problem Overview: write a console application that computes and displays the total payroll for hourly employees at a company. Each employee is represented by a record in a file called payroll.txt. A record consists of the following: Employee name (ast, first) Employee title (B or M) Hours worked Rate per hour you must read in all of the records from the file. These records are representative of a two week pay period, where the expected hours worked is so hours. You may assume the file does not consist of more than 200 records. will need to write an algorithm that traverses through the records and determines payment for each employee based on the following Basic Employee Payment hours worked rate per hour (excluding overtime) Overtime 6. rate per hour (for each hour over 40 hours worked per week) Total payment payment overtime Manager M) Payment hours worked rate per hour (excluding overtime) overtime rate per hour (for each hour over 40 hours worked per week) Total payment payment overtime you will need to write the following information to another file called paid trt: Total payroll (sum of all employees' total payments) Average total payment Max total payment Min total payment Design Requirements For this problem you must define the following struc type: struct employee char name[100 employee's name last, first char title "B worked, total or 'M double hours of hours worked hour double pay rate pay rate double payment total payment for the (2 weeks) pay period you Employee will

Explanation / Answer

// C++ code
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string> // std::string, std::to_string
#include <math.h>
#include <fstream>

using namespace std;

typedef struct employee
{
char name[100];
char title;
double hours_worked;
double payrate;
double payment;
  
}Employee;

int main()
{
int size = 0;
double total = 0, average, min, max;
Employee payroll[1];
ifstream inFile ("payroll.txt");
if (inFile.is_open())
{
while ( true )
{
if(inFile.eof())
break;

inFile.ignore();
inFile.getline(payroll[size].name, 20);
inFile >> payroll[size].title;
inFile >> payroll[size].hours_worked;
inFile >> payroll[size].payrate;

if(payroll[size].title == 'M')
{
if(payroll[size].hours_worked >= 80)
payroll[size].payment = (80)*payroll[size].payrate;
else
payroll[size].payment = (payroll[size].hours_worked)*payroll[size].payrate;

int overtime = payroll[size].hours_worked -80;
if(overtime > 0)
payroll[size].payment = payroll[size].payment + 1.6*overtime;
}

else
{
if(payroll[size].hours_worked > 80)
payroll[size].payment = (80)*payroll[size].payrate;
else
payroll[size].payment = (payroll[size].hours_worked)*payroll[size].payrate;

int overtime = payroll[size].hours_worked -80;
if(overtime > 0)
payroll[size].payment = payroll[size].payment + 1.7*overtime;
}

if(size == 0)
{
min = payroll[size].payment;
max = payroll[size].payment;
}

if(payroll[size].payment > max)
{
max = payroll[size].payment;
}
if(payroll[size].payment < min)
{
min = payroll[size].payment;
}

cout << payroll[size].name << endl;
cout << payroll[size].hours_worked << endl;
cout << payroll[size].payrate << endl;
cout << payroll[size].payment << endl;

total = total + payroll[size].payment;
size++;

  
}
inFile.close();
}
else cout << "Unable to open file";

average = total/size;

ofstream outFile ("paid.txt");
if (outFile.is_open())
{
outFile << "Total: $" << total << endl;
outFile << "Average: $" << average << endl;
outFile << "Max: $" << max << endl;
outFile << "Min: $" << min << endl;

outFile.close();
}
else cout << "Unable to open file";
return 0;
}


/*
payroll.txt
Smith, Susan
B
80.0
17.76
Sanders, Ferd
M
87.25
23.45
Kerr, Heidi
M
80.0
47.86
Russo, Rick
B
83.75
12.15

paid.txt
Total: $8113.9
Average: $2028.48
Max: $3828.8
Min: $977.1


*/