Question: You will write a program in C++ that performs the following tasks (read and understand number 6 and 7): (1) Command line arguments are to
You will write a program in C++ that performs the following tasks (read and understand number 6 and 7):
(1) Command line arguments are to be used to open the input file and the output file. The first attempt for the open is using the file names provided as command line arguments. The first argument is the input file and the second is the output file. The program is to test for the correct number of arguments. If an incorrect number of arguments is used, output a message and terminate the program run the sample solution to see what the message is.
(2) Open a user-specified file for input. If the input file name provided as a command line argument fails to open successfully, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section #1), obtains a new file name, echo prints the filename and tries to open the new file. The loop continues until the user successfully enters a valid file name or presses ctrl-c to exit. The first file name tried will come from the command line (hints #12)
(3) Open a user-specified file for output. If the output file name provided as a command line argument fails to open successfully, enter into a loop that prints out an error message, resets the output file stream variable (see the hints section #1), obtains a new file name, echo prints the filename and tries to open the new file. The loop continues until the user successfully enters a valid file name or presses ctrl-c to exit. The first file name tried will come from the command line (hints #12)
(4) If the input file is empty, your program shall write a message to the terminal AND the output file indicating that the input file was empty. Note if the input file is empty, an empty input file message only is written to the output file (no header information). (see the hints section #2)
(5) All other output is to be written to the output file
(6) The input file contains integer assignment scores for several students (one student and scores per line). For each student in the file, the program reads a students last name, first name, their quiz grades, their homework grades and their exam scores. Score values are in the range 0 to 100 inclusive. Look at all of the provided input files to see what the information looks like.
(7) The first line in the input file contains 3 integer values separated by spaces: The number of quiz scores, the number of homework grades and the number of exam scores. These values are used with count controlled loops that read in the score information for each student.
(8) The second line in the input file is the key line (The first and last names for the key line are "Key) which provides the maximum score for each assignment. Non empty files will have a key line and information for zero or more students. Empty files will contain no information. (9) Column header information and the key values are written to the output file as shown by running the sample solution. All column values are placed in a specific field width as specified in hints section #10.
(10) As shown in the sample solution, print a summary of each students information:
a. The number associated with the student (from their order in the input file)
b. Up to 10 characters (use substring function) of the last name,
c. Up to 5 characters (use substring function) of the first name,
d. The total of the quiz scores,
e. The total of the homework scores,
f. The total of the exam scores, and
g. The students average (sum of their scores divided by the sum of the key values)
Print out the average as a percent with a precision of 2 decimal places (i.e. 67.87).
(11) If one or more students are in the class, compute and output the class average after the information for all students has been read and output, Compute and output the class average. If no student information is in the file output a message to the output file and the terminal
Sample Input:
4 4 2 Key Key 10 10 10 10 20 20 20 20 100 100 Franklin Ben 10 10 10 10 20 20 20 20 100 100 Washingtonian George 10 10 0 10 20 0 0 20 100 80
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
