|
|
|
|
|
|
|
The next step is to examine each module at level 1 and answer this question: If the level-2 modules (if any) are assumed to be correct, will this level1 module do what it is supposed to do? We simply repeat the walk-through process for each module, starting with its particular precondition. In this example, there are no level-2 modules, so the level-1 modules must be complete. |
|
|
|
|
|
|
|
|
Get Data correctly reads in five valuescode, size1, size2, size3, and numOrderedthereby satisfying its postcondition. (The next refinement is to code this instruction in C++. Whether it is coded correctly or not is not an issue in this phase; we deal with the code when we perform testing in the implementation phase.) |
|
|
|
|
|
|
|
|
Calculate Lumber Amount assigns to variable boardFeet the result of multiplying the contents of size1, size2, size3 (itself multiplied by the literal 12), and numOrdered, and dividing by BOARD_FT_INCHES. That's the correct formula for computing board feet, so the step is correct and the calculated value is printed. Calculate Lumber Amount meets its required postcondition. |
|
|
|
|
|
|
|
|
Calculate Plywood Amount assigns to the variable fullSheets the result of dividing size1 by size2, multiplying by size3 (itself multiplied by the literal 12), WIDTH_INCHES, and numOrdered, and dividing by PLYWOOD_INCHES. This is the correct formula for computing full sheets of plywood, so this step is correct and the calculated value is printed. Calculate Plywood Amount also meets its required postcondition. |
|
|
|
|
|
|
|
|
Once we've completed the algorithm walk-through, we have to correct any discrepancies and repeat the process. When we know that the modules do what they are supposed to do, we start translating the top-down design into our programming language. |
|
|
|
|
|
|
|
|
We need to fix the problem we discovered in the algorithmnamely, that the main module does not guarantee the required precondition for Calculate Plywood Amount. We have to change the main module so that the assertion code equals P is true before Calculate Plywood Amount is entered. Here's the revised main module: |
|
|
|
|
|
|
|
|
Get data
IF code equals L
Calculate lumber amount
IF code equals P
Calculate plywood amount |
|
|
|
|
|
|
|
|
|
The main module now sees to it that data has been input to the five variables and that code contains the letter P before Calculate Plywood Amount is executed. This change corrects the problem we found in the walk- |
|
|
|
|
|