< previous page page_748 next page >

Page 748
Here is the program that implements our design. To conserve space we have omitted the loop invariants.
//******************************************************************
// Absentee program
// This program examines absentee data across departments for a
// week.  Percentage differences from the average per department
// are written to an output file, along with a summary bar chart
// showing percent of total absences on each day of the week
//******************************************************************
#include <iostream.h>
#include <iomanip.h>   // For setw()
#include <fstream.h>   // For file I/O

const int NUM_DEPTS = 6;     // Number of departments in the company

enum DayType {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY};
enum DeptType {A, B, C, D, E, F};

typedef int TableType[NUM_DEPTS][5]; // 2-dimensional array type for
                                     //   department vs. day of week
typedef char ChartType[10][5];       // 2-dimensional array type for
                                     //   percent vs. day of week

void ComputeAverages( const TableType, float[] );
void GetData( TableType, ifstream& );
void OpenForInput( ifstream& );
void OpenForOutput( ofstream& );
void SetAsterisks( ChartType, DayType, float );
void Summarize( const TableType, ChartType );
int  TotalAbsences( const TableType );
void WriteBarChart( const ChartType, ofstream& );
void WriteTable( const TableType, const float[], ofstream& );

int main()
{
    TableType absenteeData;          // Absences by dept. and day
    ChartType barChart;              // Summary chart of percentages
    float     average[NUM_DEPTS];    // Array of department averages
    ifstream  dataFile;              // Input file of absentee data
    ofstream  reportFile;            // Output file receiving report

    OpenForInput(dataFile);
    if ( !dataFile )
        return 1;
    OpenForOutput(reportFile);
    if ( !reportFile )
        return 1;

 
< previous page page_748 next page >