Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming Question: Suppose that students enrolled in one course are required to take four tests, and each students final grade for this course is

C Programming Question:

Suppose that students enrolled in one course are required to take four tests, and each students final grade for this course is the average of his/her grades of these four tests. This question asks you to write a program that can be used to compute the lowest final grade, highest final grade and the average final grade.

General Requirements: Use a5q1.c as the name of your C source code file. We will use the following command on bluenose to compile your program: gcc -std=c99 -o grades a5q1.c

Your program should NOT print anything to prompt for user input. As many numbers have to be read from stdin to test your programs, you are expected to use input redirection to read the input from a file. More precisely, you can run your program using the following command: ./grades < grades.1

In the above command, the file grades.1 is a plain text file of the following format:

(a) The first line has one integer. If this integer is 1, 2, or 3, then you are asked to compute the lowest, highest, or average final grade, respectively.

(b) The second line also has one integer, and it is the number of students.

(c) Starting from the third line, each line stores the grades of one student. More precisely, it contains four integers (separated by spaces) in the range [0, 100], which are grades this student obtained in the four required tests.

For example, consider the following input file:

1

3

90 80 77 79

65 78 81 88

92 91 95 93

It means that you are asked to find out the lowest final grade. There are three students. The first student got 90, 80, 77, 79 as grades in his four tests, and so on.

Your program should then compute the lowest, highest or average final grade according to the first integer read, and print the result as a floating point number, keeping two digits after the decimal point. A trailing newline is also printed. For this input, the first students final grade is (90 + 80 + 77 + 79)/4 = 78, which is the lowest among the three students. Thus the output is: 78.00

Error Handling: You can assume that user input contains integers only. However, your program should print an appropriate error message and terminate in each of the following cases: (a) The first number of the input is not 1, 2, or 3 (i.e., an incorrect option is given).

(b) The second number is not positive. 2

(c) Each grade in the input is not an integer in the range [0, 100]. If there is more than one problem with user input, your program just has to detect one of them. Testing: To test your program automatically, we will use it as a UNIX filter. For the example above, we will test it using the following command in the directory containing the executable program (assume that grades.1 is the input file) ./grades < grades.1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What lessons in intervention design, does this case represent?

Answered: 1 week ago