Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, design and implementation with C code. The example provided uses sequential, repetition statements and nested repetition statements.
This program will calculate the average of 3 exams for 5 students. The program will ask the user to enter 5 student names. For each of the students, the program will ask for 3 exam scores. The average exam score for each student will be calculated and printed.
Starting with this project, the interactions between the program and the user are getting complicated enough to justify a new section before the Analysis section – a section which will eventually become the User’s Guide. This section is a rather detailed presentation of how the program and the user will interact. A little reflection should make it apparent that neither the Analysis nor the Test Plan can really proceed without an understanding of how the program will work from the user’s perspective.
At the moment, the exact interaction is not defined by the Program Description, so this is our chance to make that interaction clear and convenient, and we will make choices. In this case, we choose to enter the 3 numbers, followed by a name. There should be spaces between the numbers and the between the third number and the student’s name. For this program, we will allow all the information to be on a single line. Here is an example, the prompt in black, the user input in red:
Enter 3 grades and the student’s name: 88.76 93 98.22 Mary
Page 2 of 9
New concept: reading, storing and printing a string input from the user. This is going to require research or an example.
Required storage: float data: new grade, sum of grades, average of those grades string data: student’s name
Math: sum = sum + new grade average = sum / 3
Example of one student: input: 70 80 90 Jane sum = 0 sum = sum + 70 sum = sum + 80 sum = sum + 90 sum is 240 at this point average = 240 / 3 = 80
Output for one student Average for Jane is 80
Looping: for 5 students o reset sum o for 3 grades get grades o get name o compute average o print result for one student end for 5 students