< previous page page_221 next page >

Page 221
Main Module                                                                                        Level 0
Get data
Test data
IF data OK
  Calculate average
  Print message indicating status
ELSE
  Print Invalid Data: Score(s) less than zero.
Which of these steps require(s) expansion? Get data, Test data, and Print message indicating status all require multiple statements in order to solve their particular subproblem. On the other hand, we can translate Print Invalid Data: directly into a C++ output statement. What about the step Calculate average? We can write it as a single C++ statement, but there's another level of detail that we must inthe actual formula to be used. Because the formula is at a lower level of detail than the rest of the main module, we chose to expand Calculate average as a Level 1 module.

Get Data                                                                                        Level 1
Prompt for input
Read studentID, test1, test2, test3
Print studentID, test1, test2, test3

Test Data
IF test1 < 0 OR test2 < 0 OR test3 < 0
    Set dataOK = FALSE
ELSE
    Set dataOK = TRUE/

Calculate Average
Set average = (test1 + test2 + test3) / 3.0

 
< previous page page_221 next page >