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

A company hired 10 temporary workers who are paid hourly and you are given a dat

ID: 3684809 • Letter: A

Question

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 computes each employee’s weekly pay and the average salary of all the workers. The program then outputs the weekly pay of each employee, the average weekly pay, and the     names of all the employees whose pay is greater than or equal to the average pay. If the number of hours worked in a week is more than 40 hours, 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, and a two-dimensional array of 10 rows            and 3 columns to store the number of hours an employee worked in a week, the hourly         pay rate, and the weekly pay. 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 the names of all the employees whose pay is greater than or equal to the average weekly pay, and a function to output each employee’s data.

Salary 875.00 13.25 1026.88 797.50 14.751253.75 656.25 750.00 973.75 20.00 1400.00 18.75 1453.13 292.50 Hrs Worked Pay Rate 12.50 Name Johnson Aniston Cooper Gupta Blair Clark Kennedy Bronson Sunny Smith 60.00 65.00 50.00 70.00 55.00 40.00 45.00 60.00 65.00 30.00 14.50 10.50 18.75 20.50 9.75 Agerage Salary: $947.88 Employees whose salaries are greater than or equal to the average salary. Aniston Gupta Kennedy Bronson Sunny

Explanation / Answer

#include<iostream>
#include<fstream>

using namespace std;

// function prototype
void readFileData(string name[], double arr[][3]);
void calculatePay(double arr[][3]);
void displayAllEmp(string name[], double arr[][3]);
double averageSalary(double arr[][3]);
void dispalyAboveAvg(string name[], double arr[][3]);

int main(){

   string name[10];
   double arr[10][3]; // arr[0] -number of hours, arr[1] - pay rate, arr[2] - weekly pay
  
   readFileData(name, arr);
  
   calculatePay(arr);
  
   displayAllEmp(name, arr);
  
   dispalyAboveAvg(name, arr);
  
   return 0;
}

// function to read data from file
void readFileData(string name[], double arr[][3]){
   int i = 0;
  
   ifstream input;
   char fileName[10];
   cout<<"Enter file name: ";
   cin>>fileName;
  
   input.open(fileName);
  
   while(i<10){
       input>>name[i]>>arr[i][0]>>arr[i][1];
       i++;
   }
}

void calculatePay(double arr[10][3]){
  
   for(int i=0; i<10; i++){
       int numberOfHours = arr[i][0];
      
       if(numberOfHours > 40){
           arr[i][2] = 40*arr[i][1] + (numberOfHours-40)*arr[i][1]*1.5;
       }
       else{
           arr[i][2] = numberOfHours*arr[i][1];
       }
   }
}

void displayAllEmp(string name[], double arr[][3]){
  
   cout<<"Name"<<"           "<<"Hrs Worked"<<"           "<<"Pay Rate"<<"       "<<"Salary"<<endl;
   for(int i=0; i<10; i++){
       cout<<name[i]<<"       "<<arr[i][0]<<"           "<<arr[i][1]<<"           "<<arr[i][2]<<endl;
   }
}

double averageSalary(double arr[][3]){
   double sum = 0;
   for(int i=0; i<10; i++){
       sum = sum + arr[i][2];
   }
  
   return sum/10;
}
void dispalyAboveAvg(string name[], double arr[][3]){
   //getting average salary
  
   double average = averageSalary(arr);
  
   for(int i=0; i<10; i++){
       if(arr[i][2] >= average)
           cout<<name[i]<<" ";
   }
   cout<<endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote