|
|
|
|
|
|
|
Problem-Solving case study Warning Notices |
|
|
|
|
|
|
|
|
Problem: Many universities send warning notices to freshmen who are in danger of failing a class. Your program should calculate the average of three test grades and print out a student's ID number, average, and whether or not the student is passing. Passing is a 60-point average or better. If the student is passing with less than a 70 average, the program should indicate that he or she is marginal. |
|
|
|
|
|
|
|
|
Input: Student ID number (of type long) followed by three test grades (of type int). On many personal computers, the maximum int value is 32767. The student ID number is of type long (meaning long integer) to accommodate larger values such as nine-digit Social Security numbers. |
|
|
|
|
|
|
|
|
The input values (echo print) |
|
|
|
|
|
|
|
|
Student ID number, average grade, passing/failing message, marginal indication, and error message if any of the test scores are negative |
|
|
|
|
|
|
|
|
Discussion: To calculate the average, we have to read in the three test scores, add them, and divide by 3. |
|
|
|
|
|
|
|
|
To print the appropriate message, we have to determine whether or not the average is below 60. If it is at least 60, we have to determine if it is less than 70. |
|
|
|
|
|
|
|
|
If you were doing this by hand, you probably would notice if a test grade was negative and question it. If the semantics of your data imply that the values should be nonnegative, then your program should test to be sure they are. We test to make sure each grade is nonnegative, using a Boolean variable to report the result of the test. Here is the main module for our algorithm. |
|
|
|
|
|