< previous page page_368 next page >

Page 368
// Precondition:
//     dataFile has been successfully opened
//  && For each department, the file contains a department ID,
//     number of days, and one sales figure for each day
// Postcondition:
//     IF input of deptID failed due to end-of-file
//          deptID and deptSales are undefined
//     ELSE
//          The data file reading marker has advanced past one
//          department's data
//       && deptID == department ID number as read from the file
//       && deptSales == sum of the sales values for the department
{
    int   numDays;  // Number of business days in the month
    int   day;      // Loop control variable for reading daily sales
    float sale;     // One day's sales for the department

    dataFile >> deptID;
    if ( !dataFile )             // Check for EOF
        return;                  // If so, exit the function

    dataFile >> numDays;
    deptSales = 0.0;
    day =1;                      // Initialize loop control variable
    while (day 
 numDays
    {
        dataFile >> sale;
        deptSales = deptSales + sale;
        day++;                   // Update loop control variable
    }
}
//******************************************************************

void PrintData( /* in */ int   deptID,       // Department ID number
                /* in */ int   storeNum,     // Store number
                /* in */ float deptSales )   // Total sales for the
                                             // department
// Prints the department ID number, the store number, and a
// bar graph of the sales for the department.  The bar graph
// is printed at a scale of one mark per $500

 
< previous page page_368 next page >