|
|
|
|
|
|
|
// Postcondition:
// A line of the bar chart has been printed with one * for
// each $500 in sales, with fractions over $250 rounded up
// && No stars have been printed for sales <= $250
{
cout << setw(12) << Dept << deptID << endl;
cout << setw(3) << storeNum << ;
while (deptSales > 250.0)
{
cout << * ; // Print * for each $500
deptSales = deptSales - 500.0; // Update loop control
} // variable
cout << endl;
} |
|
|
|
|
|
|
|
|
Testing: In addition to the testing that was recommended for the original Graph program in Chapter 7, the new program should be run with data sets that verify the new data validation code. For example, a data set with mismatched department ID numbers should be tried, as well as some incomplete data sets. |
|
|
|
|
|
|
|
|
We have not changed the overall design of the Graph programit still consists of the same collection of modules. However, we have changed the roles of some of the modules to make them more robust in dealing with invalid data. For example, if either file ends prematurely or the department IDs are not the same for both stores, then an error message is printed. (More data validation could be added to this program, such as testing for negative sales.) |
|
|
|
|
|
|
|
|
Each of the error messages in the Graph program describes the exact error that caused the message to be printed. This is effective programming practice because it aids the user of the program in determining what is wrong with the data. (Imagine how hard this would be if all the error messages just said Data error.) |
|
|
|
|
|
|
|
|
Problem-Solving Case Study Starship Weight and Balance |
|
|
|
|
|
|
|
|
Problem: The company you work for has just upgraded its fleet of corporate aircraft by adding the Beechcraft Starship-1. As with any airplane, it is essential that the pilot know the total weight of the loaded plane at takeoff and its center of gravity. If the plane weighs too much, it won't be able to lift |
|
|
|
|
|