Answered step by step
Verified Expert Solution
Link Copied!

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 10 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
1) computes each employees weekly pay and the average salary of all employees.
2) 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 40, then the pay rate for the hours over 40 is 1.5 times the regular hourly rate.
Use two parallel arrays:
a one-dimensional array to store the names of all the employees (Name)
a two-dimensional array of 10 rows and 3 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 =10;
const int COLS =3;
Salary output: Show fixed two digits after decimal point setprecision(2).
A sample output
Name Hrs Worked Pay Rate Salary
Johnson 60.0012.50875.00
Aniston 65.0013.251026.88
Cooper 50.0014.50797.50
............
Average Salary: $947.88
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 23896) exited with code 1.
Press any key to close this window ..."
#include
#include
#include
#include
using namespace std;
const int NUM_EMPLOYEES =10;
// Function to read data from a file into arrays
void readData(string names[], double hrsWorked[][3]){
ifstream inputFile("employee_data.txt");
if (!inputFile){
cerr << "Error opening file." << endl;
exit(1);
}
for (int i =0; i < NUM_EMPLOYEES; i++){
inputFile >> names[i];
inputFile >> hrsWorked[i][0]; // Hours worked
inputFile >> hrsWorked[i][1]; // Hourly pay rate
}
inputFile.close();
}
// Function to determine the weekly pay
double calculatePay(double hours, double payRate){
if (hours <=40){
return hours * payRate;
}
else {
double regularPay =40* payRate;
double overtimePay =(hours -40)*(payRate *1.5);
return regularPay + overtimePay;
}
}
// Function to output each employee's data
void outputData(string names[], double hrsWorked[][3]){
cout << "Name\tHrs Worked\tPay Rate\tSalary"<< endl;
for (int i =0; i < NUM_EMPLOYEES; i++){
double hours = hrsWorked[i][0];
double payRate = hrsWorked[i][1];
double salary = calculatePay(hours, payRate);
cout << names[i]<<"\t"<< fixed << setprecision(2)<< hours <<"\t\t"<< payRate <<"\t\t"<< salary << endl;
}
}
// Function to calculate and output the average salary
void outputAverageSalary(double hrsWorked[][3]){
double totalSalary =0.0;
for (int i =0; i < NUM_EMPLOYEES; i++){
double hours = hrsWorked[i][0];
double payRate = hrsWorked[i][1];
double salary = calculatePay(hours, payRate);
totalSalary += salary;
}
double averageSalary = totalSalary / NUM_EMPLOYEES;
cout << "Average Salary: $"<< fixed << setprecision(2)<< averageSalary << endl;
}
// Function to output names of employees with salary greater than or equal to average
void outputAboveAverage(string names[], double hrsWorked[][3]){
double totalSalary =0.0;
for (int i =0; i < NUM_EMPLOYEES; i++){
double hours = hrsWorked[i][0];
double payRate = hrsWorked[i][1];
double salary = calculatePay(hours, payRate);
totalSalary += salary;
}
double averageSalary = totalSalary / NUM_EMPLOYEES;
cout << "Salary Greater than Avg:" << endl;
for (int i =0; i < NUM_EMPLOYEES; i++){
double hours = hrsWorked[i][0];
double payRate = hrsWorked[i][1];
double salary = calculatePay(hours, payRate);
if (salary >= averageSalary){
cout << names[i]<<"";
}
}
cout << endl;
}
int main(){
string names[NUM_EMPLOYEES];
double hrsWorked[NUM_EMPLOYEES][3]; //0- Hours worked, 1- Hourly pay rate
readData(names, hrsWorked);
outputData(names, hrsWorked);
outputAverageSalary(hrsWorked);
outputAboveAverage(names, hrsWorked);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

1.2 Describe who performs HRM.

Answered: 1 week ago