|
|
|
|
|
|
|
// Print totals
cout << endl;
cout << Total Units Ordered: << setw(9) << totalUnits
< setw(21) < Total: < setw(12) < totalAmount < endl;
return 0;
} |
|
|
|
|
|
|
|
|
Testing: Because program Invoice is so complex, we discuss testing for it both here and in the next section. Here we look at the important points to watch for in testing data sets with typical values. |
|
|
|
|
|
|
|
|
The output from this program, given valid test data, is an invoice consisting of three sections. The first section is the company name and address and the column headings. Carefully examine this section of the output for spelling mistakes, proper centering of the name and address, and correct spacing of the column headings. |
|
|
|
|
|
|
|
|
The second section is the list of items being shipped. There should be one line in this section for each line of input. Check that the first and last lines of data have been processed correctlyit's in these lines that errors in loop control most often appear. Make sure that the columns of numbers are aligned under the appropriate headings. Compare the output in the Amount column with your hand-calculated results. |
|
|
|
|
|
|
|
|
The third section of the output consists of the totals. Look for spelling and spacing errors, and compare the printed values against your hand calculated results. |
|
|
|
|
|
|
|
|
In Chapter 5, we saw that an algorithm walk-through can be used to test a design before it is implemented. With this technique, we verify that each module's precondition is true before it executes and that its postcondition is true after it executes. Loops present some special problems in performing a walk-through because each iteration can behave differently. In order to test a data-dependent loop design, we would have to try every possible combination of input. In many cases, this is not practical because the possibilities are too numerous, if not infinite. |
|
|
|
|
|
|
|
|
What we would like to do is treat a loop as a separate module, so we can use our standard walk-through technique. But in order to establish a fixed |
|
|
|
|
|