112 Control Structures: Part 1 Chapter 4 Software (Msn web hosting)
112 Control Structures: Part 1 Chapter 4 Software Engineering Observation 4.5 Many algorithms can be divided logically into three phases an initialization phase that initializes the program variables, a processing phase that inputs data values and adjusts program variables accordingly and a termination phase that calculates and prints the results. The pseudocode algorithm in Fig. 4.8 solves the more general class-averaging problem. This algorithm was developed after only two levels of refinement. Sometimes more levels are necessary. Software Engineering Observation 4.6 The programmer terminates the top-down, stepwise refinement process when the pseudocode algorithm is specified in sufficient detail for the programmer to convert the pseudocode to a C# program. Implementing the C# program then normally occurs in a straightforward manner. The C# program for this pseudocode is shown in Fig. 4.9. Notice from the output that each grade entered is an integer, although the averaging calculation is likely to produce a number with a decimal point. The type int cannot represent real numbers, so this program uses data type double to handle floating-point numbers. The program also introduces the cast operator (line 44) to handle the type conversion for the averaging calculation. These features are explained in detail in our discussion of Fig. 4.9. 1 // Fig. 4.9: Average2.cs 2 // Class average with sentinel-controlled repetition. 3 4 using System; 5 6 class Average2 7 { 8 static void Main( string[] args ) 9 { 10 int total, // sum of grades 11 gradeCounter, // number of grades entered 12 gradeValue; // grade value 13 14 double average; // average of all grades 15 16 // initialization phase 17 total = 0; // clear total 18 gradeCounter = 0; // prepare to loop 19 20 // processing phase 21 // prompt for input and convert to integer 22 Console.Write( “Enter Integer Grade, -1 to Quit: ” ); 23 gradeValue = Int32.Parse( Console.ReadLine() ); 24 25 // loop until a -1 is entered by user 26 while ( gradeValue != -1 ) 27 { 28 // add gradeValue to total 29 total = total + gradeValue; Fig. 4.9 Class-average program with sentinel-controlled repetition. (Part 1 of 2.)
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services