< previous page page_788 next page >

Page 788
coding in C++. We have also shown two ways of representing the logical structure of a machine record in a shop inventory. The first used a record where all the components in an entry were defined (made concrete) at the same time. The second used a hierarchical record where the dates and statistics describing a machine's history were defined in lower-level records.
Let's look again at the two different ways in which we represented our logical data structure.
typedef char String50[51];

// ** Version 1 **

struct MachineRec
{
    int      idNumber;
    String50 description;
    float    failRate;
    int      lastServiceMonth;   // Assume 1..12
    int      lastServicedDay;    // Assume 1..31
    int      lastServicedYear;   // Assume 1900..2050
    int      downDays;
    int      purchaseDateMonth;  // Assume 1..12
    int      purchaseDateDay;    // Assume 1..31
    int      purchaseDateYear;   // Assume 1900..2050
    float    cost;
};

// ** Version 2 **

struct DateTye
{
    int month;  // Assume 1..12
    int day;    // Assume 1..31
    int year;   // Assume 1900..2050
};
struct StatisticsType
{
    float    failRate;
    DateType lastServiced;
    int      downDays;
};
struct MachineRec
{
    int            idNumber;
    String50       description;
    StatisticsType history;
    DateType       purchaseDate;
    float          cost;
};

 
< previous page page_788 next page >