|
|
|
|
|
|
|
struct DailyAbsences
{
int byDepartment[NUM_DEPTS]; // To be indexed by DeptType
};
struct DeptAbsences
{
int byDay[5]; // To be indexed by DayType
};
DailyAbsences tablel[5]; // To be indexed by DayType
DeptAbsences table2[NUM_DEPTS]; // To be indexed by DeptType |
|
|
|
|
|
|
|
|
table1 represents the data by day of the week; table2 represents the data by department. The two representations are pictured in Figures 14-7 and 14-8. |
|
|
|
|
|
|
|
|
table1 and table2 provide another example of data abstraction. In the first representation, the fact that the absences are recorded by day of the week is the important feature. The detail that the absences are further broken down by department is pushed to a lower level. Conversely, in the second representation, the fact that the absences are further broken down by day of the week is pushed to a lower level. In the two-dimensional array representation, both featuresrecording by department and recording by day of the weekare equally important (see Figure 14-9). |
|
|
|
|
|
|
|
|
The best representation for a particular problem is the one that reflects the emphasis of the processing within the problem. We can determine this emphasis by looking at the questions that are being askedthat is, the results to be computed. If the primary processing involves absences by day of the week, the first structure is best. If the primary processing involves absences by department, the second representation is best. If both aspects of the processing are equally important, the two-dimensional array representation is best. |
|
|
|
|
|
|
|
|
In this particular problem, management asks for absentee patterns across departments; therefore, the second record structure, table2, is a better choice. In fact, the parallel array average, which is used in the processing, can be incorporated into the struct type DeptAbsences. |
|
|
|
|
|
|
|
|
Figure 14-7
Absence Records by Day |
|
|
|
|
|