Question

In: Computer Science

C++ Instructions A company hired 10 temporary workers who are paid hourly and you are given...

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:

  • 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 employee’s 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

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 ...

Solutions

Expert Solution

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


Related Solutions

Write a program that calculates pay for either hourly paid workers or salaried workers. Hourly paid...
Write a program that calculates pay for either hourly paid workers or salaried workers. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are payed their regular salary plus any bonus they may have earned. The program should declare two structures for the following data: • Hourly Paid ◦HoursWorked ◦ HourlyRate • Salaried ◦ Salary ◦ Bonus The program should also declare a structure with two members. Each member should be a...
Write a C++ program that calculates pay for either hourly paid workers or salaried workers.
Write a C++ program that calculates pay for either hourly paid workers or salaried workers. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are payed their regular salary plus any bonus they may have earned. The program should declare two structures for the following data:• Hourly Paid◦ HoursWorked◦ HourlyRate• Salaried◦ Salary◦ BonusThe program should also declare a structure with two members. Each member should be a structure variable: one for the...
A company pays its employees as managers (who receive a fixedweekly salary), hourly workers (who...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company works on only one...
Suppose that in an industry, workers are hired on an hourly basis. Labor costs are variable...
Suppose that in an industry, workers are hired on an hourly basis. Labor costs are variable costs, in that the firm needs to hire more workers (for more hours) to increase production, and the firm can choose to hire zero workers if it does not want to produce. Suppose that market wages go up, and hiring workers becomes more expensive per hour, while other costs remain the same. Consider how this will affect the cost curves for a firm in...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half”—i.e., 1.5 times their hourly wage—for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money for each of the items they produce—each pieceworker in this company works on only one type of item). Write...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company works on only one...
If firms increase the hourly wage paid to all workers then (all else the same) this...
If firms increase the hourly wage paid to all workers then (all else the same) this will tend to: Group of answer choices increase the price of the goods sold by the firms because of a decrease in supply. increase the price of the goods sold by the firms because of an increase in supply. decrease the price of the goods sold by the firms because of a decrease in supply. decrease the price of the goods sold by the...
About 5​% of hourly paid workers in a region earn the prevailing minimum wage or less....
About 5​% of hourly paid workers in a region earn the prevailing minimum wage or less. A grocery chain offers discount rates to companies that have at least 30 employees who earn the prevailing minimum wage or less. Complete parts​ (a) through​ (c) below. ​(a) Company A has 299 employees. What is the probability that Company A will get the​ discount?
About 5​% of hourly paid workers in a region earn the prevailing minimum wage or less....
About 5​% of hourly paid workers in a region earn the prevailing minimum wage or less. A grocery chain offers discount rates to companies that have at least 30 employees who earn the prevailing minimum wage or less. Complete parts​ (a) through​ (c) below. ​(a) Company A has 287 employees. What is the probability that Company A will get the​ discount? ​(Round to four decimal places as​ needed.) ​(b) Company B has 501 employees. What is the probability that Company...
Many universities pay their teaching assistants (TA) or associate instructors (AI) as weekly workers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 10 hours they work and “time-and-a-half”
Needs to be written in CMany universities pay their teaching assistants (TA) or associate instructors (AI) as weekly workers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 10 hours they work and “time-and-a-half”- i.e., 1.5 times their hourly wage - for overtime hours worked), commission workers (who receive $250 plus 7.1 times their gross weekly work hours), or pieceworkers (who receive a fixed amount of money for each of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT