|
|
|
|
|
|
|
//******************************************************************
void Summarize(
/* in */ const TableType absenteeData, // Table of absences
/* out */ ChartType barChart ) // Chart of percentages
// Calculates total percentages by day and represents
// the results in a bar chart
// Precondition:
// absenteeData[A..F][MONDAY..FRIDAY] are assigned
// Postcondition:
// For each day, the total number of absences over all
// departments has been computed as a percentage of total
// absences all week
// && For all j, where MONDAY <= j <= FRIDAY,
// column j of barChart has been filled with the number of
// asterisks corresponding to day j's absence percentage,
// rounded to the nearest 10 percent
{
DayType day; // Loop counter
DeptType dept; // Loop counter
float percent; // Daily percentage
int dailyTotal; // Total per day
int weeklyTotal; // Total of entire table
weeklyTotal = TotalAbsences(absenteeData);
for (day = MONDAY; day <= FRIDAY; day = DayType (day +1))
{
dailyTotal = 0;
for (dept = A; dept <= F; dept = DeptType (dept +1))
dailyTotal = dailyTotal + absenteeData[dept][day];
if (weeklyTotal > 0)
percent = float(dailyTotal) / float (weeklyTotal) * 100.0;
else
percent = 0.0;
SetAsterisks (barChart, day, percent);
}
}
//******************************************************************
|
|
|
|
|
|