110 Control Structures: Part 1 Chapter 4 Determine (Web host)
110 Control Structures: Part 1 Chapter 4 Determine the class average for the quiz The top is a single statement that conveys the overall function of the program. As such, the top is a complete representation of a program. Unfortunately, the top rarely conveys a sufficient amount of detail from which to write the C# algorithm. Therefore, we conduct the refinement process. We divide the top into a series of smaller tasks and list these in the order in which they must be performed. This results in the following first refinement: Initialize variables Input, sum up and count the quiz grades Calculate and print the class average Here, only the sequence structure has been used the steps listed are to be executed in order, one after the other. Software Engineering Observation 4.4 Each refinement, including the top, is a complete specification of the algorithm; only the level of detail in each refinement varies. To proceed to the next level of refinement (i.e., the second refinement), we commit to specific variables. We need a running total of the numbers, a count of how many numbers have been processed, a variable to receive the value of each grade and a variable to hold the calculated average. The pseudocode statement Initialize variables may be refined as follows: Initialize total to zero Initialize counter to zero Notice that only the variables total and counter are initialized before they are used; the variables average and grade (for the calculated average and the user input, respectively) need not be initialized because their values are determined as they are calculated or input. The pseudocode statement Input, sum up and count the quiz grades requires a repetition structure (i.e., a loop) that successively inputs each grade. We do not know how many grades are to be processed, thus we use sentinel-controlled repetition. The user types in legitimate grades one at a time. After the last legitimate grade is typed, the user types the sentinel value. The program tests for the sentinel value after each grade is input and terminates the loop when the user enters the sentinel value. The second refinement of the preceding pseudocode statement is then Input the first grade (possibly the sentinel) While the user has not as yet entered the sentinel Add this grade into the running total Add one to the grade counter Input the next grade (possibly the sentinel) We do not use braces around the pseudocode that forms the body of the while structure. We simply indent the pseudocode under the while to show that it belongs to the while structure.
Note: If you are looking for cheap webhost to host and run your apache application check Vision apache web hosting services