Question: The C++ program needs to calculate gross pay for each employee from the information in the employees.txt file and write out the gross pay (plus
The C++ program needs to calculate gross pay for each employee from the information in the "employees.txt" file and write out the gross pay (plus the employee ID) to a separate file. The format of the file is as follows:
There are currently 8 employees in the file but your program should work for up to 100 employees or less.
The program does the following:
1. Read in the name, ID, hours worked and pay rate from the file and put it into an array of structs of the type Employee. Define this in the main.cpp file.
2. Print the employee info to the terminal; this doesn't have to be in any nice format as long as all info is printed. Make maximum C-string sizes 250 and use getline for the name as names have spaces in them. ID's are integers and hours/ payrate are doubles.
3. Calculate the gross pay of each employee by multiplying the hours by the pay rate. Store this in the array's struct for that employee (so the struct needs a gross pay component; make this a double).
4. write the ID and gross pay of each employee out to another file called 'grosspay.txt'. Use the same format as 'employees.txt'.
Requirements:
You will design a struct called Employee. Your main function should have an array of Employee structs. The array should be able to hold up to 100 structs of Employee. You should also keep track of how many actual employees were read in.
Hint:
The names will have spaces in them. So remember to use 'getline' when reading in these values: infile.getline(employees[i].name, MAX_STR); where infile is the ifstream variable and employees is an array of Employee structs for reading in the employee information. For the ID, hours and payrate, you can use infile >> but you will need to use infile.ignore() in order to get rid of the new line at the end of the line. infile >> employees[i].ID; infile.ignore(MAX_STR,' ');
If anybody could please help me out with this code I would be extremely greatful as there are some parts I can't figure out myself.
The file in question "Employees.txt" contains the following information:
Linda Noonan 12343 30.5 12.10 Tony Franklin 42454 40.0 35.20 Mary White 34255 15.0 10.90 Randall Gunder 43243 36.75 26.31 Mark Brown 35433 39.0 19.00 Brenda McMillan 24364 8.5 20.00 Frank Lacey 84325 11.25 12.30 John Green 47283 40.0 28.33
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
