< previous page page_232 next page >

Page 232
signed is an abbreviated way of asserting that someVariable has already been assigned a meaningful value.
ModulePreconditionPostcondition
MainA letter and four integer values have been input AND Either the number of board feet or the number of plywood sheets has been calculated and displayed
Get Datacode, size1, size2, size3, and numOrdered have been input
Calculate Lumber Amountcode equals L AND size1, size2, size3, and numOrdered are assignedThe number of board feet has been computed and printed
Calculate Plywood Amountcode equals P AND size1, size2, size3, and numOrdered are assignedThe number of plywood sheets has been computed and printed

Now that we've established the preconditions and postconditions, we walk through the main module. At this point, we are concerned only with the steps in the main module, so for now we assume that each lower-level module executes correctly. At each step, we must determine the current conditions. If the step is a reference to another module, we have to verify that the precondition of that module is met by the current conditions.
First we assume that Get Data correctly inputs a letter and four integer values. Then the If statement checks to see if the letter is an L. If it is, the computer takes the Calculate Lumber Amount branch. Assuming Calculate Lumber Amount correctly calculates and prints the quantity ordered (remember, we're assuming that the lower-level modules are correct for now), that branch of the If statement is correct.
If the letter in code is not an L, the computer takes the Calculate Plywood Amount branch. Here we have a problem. The precondition of Calculate Plywood Amount asserts that the value of code is P, but the only condition that has been established is that code does not contain an L. As we have written it, the algorithm calculates the quantity of full sheets ordered if anything other than an L is entered for code. So the algorithm works as long as the data is entered correctly, but it does not catch incorrect data. This is poor design, and we return to the problem later. But first let's finish up the walk-through.

 
< previous page page_232 next page >