Question
Rewrite the code below that reads employee data from a file (hourly wage, id number, and name) using an array of employee records. Update the
Rewrite the code below that reads employee data from a file (hourly wage, id number, and name) using an array of employee records. Update the hourly wage then output a formatted report.
o The input file is named wages.in. o The output file must be named wages.rpt. o For each function make sure you are passing properly the parameters by value or by reference as is appropriate. o You must define and use global constants for: the maximum number of employee records to be read (up to 50) and minimum wage ($11.20/hour) o You must define and use a struct named Employee. This type must have three members, a double to store the hourly wage, an int to store the idNo, and a string to store the employees name. o You must use and define the following three functions; you may define more functions if you find it useful to do so. loadArraysFromFile Parameters: an ifstream connected to the input file, an Employee array for the employee records. Return: int the number of employee records read Read the employee records into the array of Employee. newHourlyWage Parameters: an Employee (this is NOT an array) Return: double the new hourly wage Determine the new hourly wage using the following method, in the given order. If the wage is less than minimum wage change it to minimum wage. If the id number starts with a 1 or 2 the employee gets a 2% raise If the id number starts with a 3 or 4 the employee gets a 2% raise then an extra 5/hour. If the id number starts with a 5 or 6 the employee gets a 4% raise then an extra 5/hour. If the id number starts with a 7 the employee gets a 5% raise then an extra 5/hour. If the id number starts with a 8 the employee gets a 5% raise then an extra 10/hour. If the id number starts with a 9 the employee gets a raise of 50/hour. The hourly wage must be ROUNDED to 2 decimal places before it is returned. writeReport Parameters: an ofstream connected to the output, an Employee array, an int storing the number of employee records read. Return: none Print the report to the output file formatted as seen in the picture below.
Here is the code that needs to be modifed with struct statements:
#include
#include
#include
using namespace std;
const int MAX_EMPLOYEES=100;
const double MINIMUM_WAGE=11.20;
// function prototypes
int loadArraysFromFile(ifstream&,double[],int[],string[]);
double newHourlyWage(int,double);
void writeReport(ofstream&,const int[],const string[],const double[],int);
int main()
{
ifstream fin; // the input stream for the file wages.in
double employeeWage[MAX_EMPLOYEES]; // the list of employee wages
int employeeIdNo[MAX_EMPLOYEES]; // the list of employee numbers
string employeeName[MAX_EMPLOYEES]; // the list of employee names
int numEmployees=0; //the number of employee records found in the file
ofstream fout; // the output stream for the file, wages.rpt
fin.open("wages.in");
numEmployees=loadArraysFromFile(fin,employeeWage,employeeIdNo,employeeName);
fin.close();
for(int i=0;i
{
employeeWage[i]=newHourlyWage(employeeIdNo[i],employeeWage[i]);
}
fout.open("wages.rpt");
writeReport(fout,employeeIdNo,employeeName,employeeWage,numEmployees);
fout.close();
return 0;
}
int loadArraysFromFile(ifstream& fin,double wageList[],int idNoList[],string nameList[])
{
int numFound=0; // the number of employee records found in the file
for(numFound=0;numFound
{
fin >> wageList[numFound] >> idNoList[numFound];
getline(fin,nameList[numFound]);
}
return numFound;
}
double newHourlyWage(int idNo,double wage)
{
if(wage
wage = MINIMUM_WAGE;
switch (idNo/1000)
{
case 1: case 2:
wage = wage * 1.02;
break;
case 3: case 4:
wage = wage*1.02 + 0.05;
break;
case 5: case 6:
wage = wage*1.04 + 0.05;
break;
case 7:
wage = wage*1.05 + 0.05;
break;
case 8:
wage = wage*1.05 + 0.10;
break;
case 9:
wage += 0.50;
break;
}
return static_cast(wage*100+0.5)/100.0;
}
void writeReport(ofstream& fout,const int idNoList[],const string nameList[],
const double wageList[],int length)
{
fout
for(int i=0;i
fout
fout
}
Here is the contents of the file:
15.85 2655 Qyzen Fess 20.17 3111 Tharan Cedrax 25.51 4463 Zenith 15.51 2413 Lt. Felix Iresso 30.85 5485 Nadia Grell 20.17 3511 T7-01 15.17 2421 Kira Carsen 10.68 1594 Doc 15.68 2964 Sergeant Rusk 26.02 4336 Lord Scourge 21.36 3168 Corso Riggs 26.19 4877 Bowdaar 15.51 2373 Risha 15.17 2471 Akaavi Spar 25.34 4252 Guss Tuno 20.34 3672 Aric Jorgan 10.68 1394 Elara Dorne 25.34 4352 M1-4X 20.85 3975 Tanno Vik 21.02 3756 Yu'un 20.34 3052 C2-N2 16.02 2066 Treek 20.17 3301 HK-51 21.53 3899 Lana Beniko 25 4170 Theron Shan 10.51 1473 Koth Vortena 25.85 4125 Senya Tirall 15.17 2661 Nico Okarr 20.51 3583 Shae Visla 11.36 1708 Blizz 26.36 4098 Dr. Loken 25.51 4743 Kaliyo 20 3730 Talos Drellik 20.17 3131 Pierce 15.34 2982 Vette 20.85 3245 Torian Cadera 20.85 3248 Xalek 20.17 3302 HK-55
Here is how the printed report should look like:
WAGE REPORT ID NUMBER NAME 2655 oyzen Fess 3111 Tha ran Cedrax 4463 Zenith Lt. Felix Iresso 2413 5485 Nadia Grell 3511 T7-01 2421 Kira Carsen 1594 Doc 2964 Sergeant Rusk 4336 Lord Scourge 3168 Corso Riggs 4877 Bowdaar 2373 Risha 2471 Akaavi Spar 4252 Guss Tuno 3672 Aric Jorgan 1394 Elara Dorne 4352 M1-4X 3975 Tanno Vik 3756 Yu un 3052 C2-N2 2066 Treek 3301 HK-51 3899 Lana Beniko 4170 Theron Shan 1473 Koth Vortena ll 4125 Senya Tira 2661 Nico Okarr 3583 Shae Visla 1708 Blizz Loken 4098 Dr Kaliyo 4743 3730 Talos ik 3131 Pierce 2982 Vette 3245 Tor Cadera 3248 Xalek 3302 HK-55 Report Ends HOURLY WAGE 16.17 20.62 26.07 15.82 32.13 20.62 15.47 11.42 15.99 26.59 21.84 11.47 15.82 15.47 25.90 20.80 11.42 25.90 21.32 21.49 20.80 16.34 20.62 22.01 25.55 11.42 26.42 15.47 20.97 11.42 26.94 26.07 20.45 20.62 15.65 21.32 21.32 20.62
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started