Question: Write a simple payroll program that would: 1. Change the structure in project #3 to a class (adding a member variable called grossPay; 2. Making
Write a simple payroll program that would: 1. Change the structure in project #3 to a class (adding a member variable called grossPay; 2. Making all member variables of the class private; 3. Add constructors, mutators, accessors, input, & output functions; 4. Write a main function to: a. Read employees records from a disk file (attached with email for project #3) the array of class defined in step 1. The text file includes records of employees. Each record includes: employees name (30 bytes), employees id (5 bytes), hourly rate(int), hours worked (int). b. Calculate the gross pay for each employee based on the hourly rate and the hours worked and store this piece of information in the member variable called grossPayof the class. c. Display on the screen all employees name and gross pay as a report. d. Display the highest gross pay of the company. e. Display the average of gross pay of the company. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Project #3:
#include
#include
#include
using namespace std;
#define MAX 5
struct Employee{ //Employee Structure
char name[30];
char emp_id[5];
int hourly_rate;
int hours_worked;
double wage;
};
int main(){
Employee emp[MAX];
ifstream in; //Created object of the ifstream
in.open("Project 3.dat"); //Call object to open the file
if(in.fail()){
cout
return 0;
}
int n=0;
while(!in.eof()){ //Loop
in>>emp[n].name>>emp[n].emp_id>>emp[n].hourly_rate>>emp[n].hours_worked;
emp[n].wage = emp[n].hourly_rate * emp[n].hours_worked;
n++;
}
for(int i=0; i for(int j=i+1; j if(emp[i].wage >emp[j].wage){ Employee temp = emp[i]; emp[i] = emp[j]; emp[j] = temp; } } } double avg_wage = 0.0; for(int i=0; i cout avg_wage += emp[i].wage; } avg_wage /= (double)n; cout return 0; } //Screenshot of Project #3 output. 
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
