Chapter 4 Control Structures: Part 1 117 Initialize (Free web space)

Chapter 4 Control Structures: Part 1 117 Initialize variables Input the ten exam grades and count passes and failures Print a summary of the exam results and decide if tuition should be raised Even though we have a complete representation of the entire program, further refinement is necessary. We must commit to specific variables. Counters are needed to record the passes and failures. A counter controls the looping process and a variable stores the user input. The pseudocode statement Initialize variables may be refined as follows: Initialize passes to zero Initialize failures to zero Initialize student to one Only the counters for the number of passes, number of failures and number of students are initialized. The pseudocode statement Input the ten quiz grades and count passes and failures requires a loop that successively inputs the result of each exam. Here, it is known in advance that there are precisely ten exam results, so counter-controlled repetition is appropriate. Inside the loop (i.e., nested within the loop) a double-selection structure determines whether each exam result is a pass or a failure, and the structure increments the appropriate counter accordingly. The refinement of the preceding pseudocode statement is While student counter is less than or equal to ten Input the next exam result If the student passed Add one to passes Else Add one to failures Add one to student counter Notice the use of blank lines to offset the If/Else control structure to improve program readability. The pseudocode statement Print a summary of the exam results and decide if tuition should be raised may be refined as follows: Print the number of passes Print the number of failures If more than eight students passed Print Raise tuition The complete second refinement appears in Fig. 4.10. Notice that blank lines also set off the While structure for program readability. The pseudocode now is refined sufficiently for conversion to C#. The C# program and sample executions are shown in Fig. 4.11.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services

Leave a Reply