|
|
|
|
|
|
|
// Precondition:
// deptID contains a valid department number
// && storeNum contains a valid store number
// && 0.0 <= deptSales <= 25000.0
// 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
{
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: We should test this program with data files that contain the same number of data sets for both stores and with data files that contain different numbers of data sets for both stores. The case where one or both of the files are empty also should be tested. The test data should include a set that generates a monthly sales figure of $0.00 and one that generates more than $25,000 in sales. We also should test the program to see what it does with negative days, negative sales, and mismatched department IDs. This series of tests would reveal that, for this program to work correctly for the furniture-store employees who are to use it, we should add several checks for invalid data. In Chapter 8, we revisit this program, adding code for data validation. |
|
|
|
|
|
|
|
|
The main function of the Graph program not only reflects our top-down design, it calls both GetData and PrintData twice. The result is a program that is shorter and more readable than one in which the code for each function is physically repeated. |
|
|
|
|
|
|
|
|
The combination of the formal parameters declared by a function and the actual parameters that are passed to the function by the caller constitutes the interface between the two functions. Errors that occur with the use of functions usually are due to an incorrect interface between the calling code and the called function. |
|
|
|
|
|