In: Computer Science
C++
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 computes each employee’s weekly pay and the average salary of all employees. 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, then the pay rate for the hours over 40 is 1.5 times the regular hourly rate.
Use two parallel arrays:
Your program must contain at least the following functions:
A sample output is:
Name | Hrs Worked | Pay Rate | Salary |
---|---|---|---|
Johnson | 60.00 | 12.50 | 875.00 |
Aniston | 65.00 | 13.25 | 1026.88 |
Cooper | 50.00 | 14.50 | 797.50 |
... | ... | ... | ... |
Average Salary: $947.88 |
Salary Greater than Avg: |
Aniston Gupta Kennedy ... |
Note:
Could you plz go through this code and let me know
if u need any changes in this.Thank You
=================================
Where we have to paste the input file in dev C++ ??
=================================
// workers.txt (input file)
Johnson 60 12.50
Aniston 65.00 13.25
Cooper 50.00 14.50
Gupta 70.00 14.75
Blair 55.00 10.50
Clark 40.00 18.75
Kennedy 45.00 20.50
Bronson 60.00 20.00
Sunny 65.00 18.75
Smith 30.00 9.75
===================================
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
// Function declarations
void readFile(int rows,int cols,string names[],double **arr);
void calculateWeeklyPay(int rows,int cols,double **arr);
double calcAvgerageSalary(int rows,int cols,double **arr);
void empsGreaterThanAvegSalary(double avg,int rows,int cols,string
names[],double **arr);
int main()
{
// Declaring constants
const int SIZE=10;
const int COLS=3;
// Creating 1-D array
string names[SIZE];
// Creating 2-D array Dynamically
double** arr = new double*[SIZE];
for (int i = 0; i < SIZE; ++i)
arr[i] = new double[COLS];
// Calling the functions
readFile(SIZE,COLS,names,arr);
calculateWeeklyPay(SIZE,COLS,arr);
double avg=calcAvgerageSalary(SIZE,COLS,arr);
empsGreaterThanAvegSalary(avg,SIZE,COLS,names,arr);
return 0;
}
/* This function will read the data from the file
* and populate those values into an array
*/
void readFile(int rows,int cols,string names[],double **arr)
{
ifstream dataIn;
dataIn.open("workers.txt");
for(int i=0;i<rows;i++)
{
dataIn>>names[i];
for(int j=0;j<cols-1;j++)
{
dataIn>>arr[i][j];
}
}
dataIn.close();
}
// This function will calculate weekly pay of each
employee
void calculateWeeklyPay(int rows,int cols,double **arr)
{
double sal=0.0;
for(int i=0;i<rows;i++)
{
if(arr[i][0]<=40)
{
sal=arr[i][0]*arr[i][1];
}
else if(arr[i][0]>=40)
{
sal=(40*arr[i][1])+(arr[i][0]-40)*arr[i][1]*1.5;
}
arr[i][2]=sal;
}
}
// This function will calculate the average salary
double calcAvgerageSalary(int rows,int cols,double **arr)
{
double sum=0.0,avg=0.0;
for(int i=0;i<rows;i++)
{
sum+=arr[i][2];
}
avg=sum/rows;
return avg;
}
/* This function will display the names of employees
* whose salary is greater than average salary
*/
void empsGreaterThanAvegSalary(double avg,int rows,int cols,string
names[],double **arr)
{
//setting the precision to two decimal places
std::cout << std::setprecision(2) <<
std::fixed;
cout<<setw(15)<<left<<"Name"<<setw(15)<<left<<"Hrs
Worked"<<setw(15)<<left<<"Pay
Rate"<<setw(15)<<left<<"Salary"<<endl;
for(int i=0;i<rows;i++)
{
cout<<setw(15)<<left<<names[i];
for(int j=0;j<cols;j++)
{
cout<<setw(15)<<left<<arr[i][j];
}
cout<<endl;
}
cout<<"Average Salary
:$"<<avg<<endl;
cout<<"Salary Greater than
Avg:"<<endl;
for(int i=0;i<rows;i++)
{
if(arr[i][2]>avg)
{
cout<<names[i]<<" ";
}
}
cout<<endl;
}
===========================================
===========================================
Output:
=====================Could you plz rate me well.Thank You