Write a program that reads a list of students marks in a course from an input file then calculates the students grades and the class average mark and grade. Your program should input the name of the file from the user (via the keyboard).
Each line in the input file contains a student ID followed by marks in homework assignments (out of 10), in lab tests (out of 50) and in the final test (out of 40). Each of these four pieces of information is separated by a tab.
Your program should write the output to an output file called results.dat as follows:
1. For each student write the following on a line: ID followed by the total mark followed by the grade separated by tabs. Assume grades are calculated according to the following table:
95-100: A
90-95: A-
85-89: B+
80-84: B
75-79: B-
70-74: C+
65-69: C
60-64: C-
55-59: D
Below 55: F
2. The class average total mark and grade should be written at the end of the output file.
3. If the class average is 80% or above your program should display on the screen the message “high average”, otherwise display “normal average.” Use the ternary operator ?: (explained below) for this step.
4. Your program should have a separate function for opening files and another function for closing the files. The function which opens the file takes as input the names (on disk) of the files to open. It returns 0 if the files are open successfully, returns 1 if the input file does not open successfully, and returns 2 if the output file does not open successfully. The function which closes the files takes as input the names of the files (on disk) to close and returns nothing.
Your program should handle the following errors and display a proper error message for each
1. File does not exist
2. Total mark is not in the range 0 to 100
Ternary operator(from MIT OpenCourseWare):
The conditional operator ?: is also another way to evaluate conditions. It operates on three operands, and is thus known as a ternary operator. Here is an example of its usage:
a = x < y ? x : y;
In this example, if the test expression evaluates to true – i.e. if x<y – then the variable a will be assigned the value that the variable x contains. Otherwise, else it will be assigned the value of the variable y.