Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instructions A company hired 1 0 temporary workers who are paid hourly and you are given a data file that contains the last name of
Instructions
A company hired temporary workers who are paid hourly and you are given a data file that contains the last name of the employees, the number of hours each employee worked in a week, and the hourly pay rate of each employee.
You are asked to write a program that
computes each employees weekly pay and the average salary of all employees.
The program then outputs:
the weekly pay of each employee,
the average weekly pay
the names of all the employees whose pay is greater than or equal to the average pay.
Note: If the number of hours worked in a week is more than then the pay rate for the hours over is times the regular hourly rate.
Use two parallel arrays:
a onedimensional array to store the names of all the employees Name
a twodimensional array of rows and columns to store the number of hours an employee worked in a week Hrs Worked the hourly pay rate Pay Rate and the weekly pay Salary
Your program must contain at least the following functions:
a function to read the data from the file into the arrays.
a function to determine the weekly pay.
a function to output each employees data.
a function to output the average salary of all employees
a function to output the names of all the employees whose pay is greater than or equal to the average weekly pay
The only global variables are the array dimensions:
const int ROWS ;
const int COLS ;
Salary output: Show fixed two digits after decimal point setprecision
A sample output
Name Hrs Worked Pay Rate Salary
Johnson
Aniston
Cooper
Average Salary: $
Salary Greater than Avg:
Aniston Gupta Kennedy
this is the code i have so far but, when i run my code i get this error and i dont know how to fix it "error opening file. process exited with code
Press any key to close this window
#include
#include
#include
#include
using namespace std;
const int NUMEMPLOYEES ;
Function to read data from a file into arrays
void readDatastring names double hrsWorked
ifstream inputFileemployeedata.txt;
if inputFile
cerr "Error opening file." endl;
exit;
for int i ; i NUMEMPLOYEES; i
inputFile namesi;
inputFile hrsWorkedi; Hours worked
inputFile hrsWorkedi; Hourly pay rate
inputFile.close;
Function to determine the weekly pay
double calculatePaydouble hours, double payRate
if hours
return hours payRate;
else
double regularPay payRate;
double overtimePay hours payRate ;
return regularPay overtimePay;
Function to output each employee's data
void outputDatastring names double hrsWorked
cout "NametHrs WorkedtPay RatetSalary endl;
for int i ; i NUMEMPLOYEES; i
double hours hrsWorkedi;
double payRate hrsWorkedi;
double salary calculatePayhours payRate;
cout namesit fixed setprecision hours tt payRate tt salary endl;
Function to calculate and output the average salary
void outputAverageSalarydouble hrsWorked
double totalSalary ;
for int i ; i NUMEMPLOYEES; i
double hours hrsWorkedi;
double payRate hrsWorkedi;
double salary calculatePayhours payRate;
totalSalary salary;
double averageSalary totalSalary NUMEMPLOYEES;
cout "Average Salary: $ fixed setprecision averageSalary endl;
Function to output names of employees with salary greater than or equal to average
void outputAboveAveragestring names double hrsWorked
double totalSalary ;
for int i ; i NUMEMPLOYEES; i
double hours hrsWorkedi;
double payRate hrsWorkedi;
double salary calculatePayhours payRate;
totalSalary salary;
double averageSalary totalSalary NUMEMPLOYEES;
cout "Salary Greater than Avg:" endl;
for int i ; i NUMEMPLOYEES; i
double hours hrsWorkedi;
double payRate hrsWorkedi;
double salary calculatePayhours payRate;
if salary averageSalary
cout namesi;
cout endl;
int main
string namesNUMEMPLOYEES;
double hrsWorkedNUMEMPLOYEES; Hours worked, Hourly pay rate
readDatanames hrsWorked;
outputDatanames hrsWorked;
outputAverageSalaryhrsWorked;
outputAboveAveragenames hrsWorked;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started