Question: Write a program that does the following: Reads 5 employee identification numbers from a file. Asks the user to enter the number of hours worked
Write a program that does the following: Reads 5 employee identification numbers from a file.
Asks the user to enter the number of hours worked during the week and pay rate of each employee.
Calculates the gross salary of each employee.
Writes to a file the employee identification number and gross salary of each employee.
The program MUST use the following parallel arrays:
an array to store 5 employee identification numbers. This array must be filled with the employee identification numbers stored in the file employee_ids.txt. (Note: Download the file from the link at the top by right clicking.)
an array to store the number of hours worked during the week by each employee. This array will be filled with input provided by the user.
an array to store the hourly pay rate of each employee. This array will be filled with input provided by the user. an array to store the gross salary of each employee. The gross salary of an employee is computed by multiplying the employee's hourly pay rate times the number of hours worked.
The program MUST have the following functions (You are allowed to use additional functions):
A function that opens the file employee_ids.txt containing the employee identification numbers. This function only opens the file for input. It doesn't read the contents of the file. The user must be asked to enter the location and name of the file. If the file specified can't be found, a loop must be used to continue to prompt the user for a valid file location and name.
A function that opens the output file for writing. This function only opens the file for output. It doesn't write the results to the file. The user must be asked to enter the location and name of the file. If the file specified is not valid, a loop must be used to continue to prompt the user for a valid file location and name. A function which reads the employee identification numbers from the input file and stores them in the appropriate array.
A function that asks the user to enter the number of hours worked during the week and pay rate of each employee, and stores the information in the corresponding arrays. The employee identification number of the employee MUST be displayed before asking the user for the employee's information. The number of hours worked must be zero or greater, and the pay rate must be $7.50 or greater. If the input provided is not valid, a loop must be used to continue to prompt the user for valid data.
A function that calculates the gross salary of each employee and stores it in the corresponding array.
A function which writes to the output file the employee indentification number and gross salary of each employee.
The output should be formatted nicely. Here is sample program run:
Enter the hours worked and pay rate for the employee with id A12345:
Hours: 20 [Enter]
Pay rate: $10.50 [Enter]
Enter the hours worked and pay rate for the employee with id B55874:
Hours: 25 [Enter]
Pay rate: $15.00 [Enter]
Enter the hours worked and pay rate for the employee with id C69851:
Hours: 30.75 [Enter]
Pay rate: $20.25 [Enter]
Enter the hours worked and pay rate for the employee with id D12458:
Hours: 35 [Enter]
Pay rate: $22.00 [Enter]
Enter the hours worked and pay rate for the employee with id E52242:
Hours: 40 [Enter]
Pay rate: $25.50 [Enter]
Output written to file:
Employee ID Gross Salary
A12345 $210.00
B55874 $375.00
C69851 $622.69
D12458 $770.00
E52242 $1020.00
Note: The above program run is just an example. The ids stored in the input file will be different!
Other Requirements:
GLOBAL VARIABLES THAT ARE NOT CONSTANTS ARE PROHIBITED! 50 POINTS WILL BE DEDUCTED FOR EACH NON-CONSTANT GLOBAL VARIABLE!
Functions that will only read the contents of an array should NOT be allowed to modify its contents!
Loops must be used to process the arrays and files!
The output must be aligned and nicely formatted!
In addition, your program must use named constants to store values that will not change during the execution of the program. The program's code must be nicely formatted and easy to read. (i.e. follow the coding guidelines mentioned in class) Points will be deducted if the code is hard to read and it's not properly formatted. Insert a comment with your name at the top of your program.
How to Submit:
Upload ONLY your source file (.cpp). Please verify you uploaded the correct file. If you upload the WRONG FILE you will receive a ZERO. You may upload your file only once. You must name your source file: Lastname_Firstname (i.e. Brown_John). Remember that programs that do NOT COMPILE will receive at most 50 POINTS.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
