|
|
|
|
|
|
|
1. Write the type declaration for a struct data type named TimeType with three members: hour, minute, and second. The hour member is intended to store integer values from 0 through 23. The other two members store values from 0 through 59. (pp. 772780) |
|
|
|
|
|
|
|
|
2. Assume a variable named now, of type TimeType, has been declared. Write the assignment statements necessary to store the time 8:37:28 into now. (pp. 772780) |
|
|
|
|
|
|
|
|
3. Declare a hierarchical record type named Interval that consists of two members of type TimeType. The members are named past and present. (pp. 782786) |
|
|
|
|
|
|
|
|
4. Assume a variable named channelCrossing, of type Interval, has been declared. Write the assignment statements necessary to store the time 7:12:44 into the past member of channelCrossing. Write the assignment statement that stores the contents of variable now into the present member of channelCrossing. (pp. 782786) |
|
|
|
|
|
|
|
|
5. Declare a variable boatTimes that is an array of Interval values to be indexed by an enumeration type named BoatNames: |
|
|
|
 |
|
|
|
|
enum BoatNames {LUCKY, MY_PRIDE, SWELL_STUFF}; |
|
|
|
 |
|
|
|
|
Then write a statement that stores the contents of variable now into the present member of the struct for the boat named Swell Stuff. (pp. 781782) |
|
|
|
|
|
|
|
|
6. Decide what form of data structure is appropriate for the following problem. A single card in a library catalog system must contain the call number, author, title, and description of a single book. (pp. 787793) |
|
|
|
|
|
|
|
|
7. What is the primary purpose of C++ union types? (pp. 786787) |
|
|
|
|
|
|
|
|
1. struct TimeType
{
int hour; // Range 0..23
int minute; // Range 0..59
int second; // Range 0..59
};
2. now.hour = 8;
now.minute = 37;
now.second = 28;
3. struct Interval
{
TimeType past;
TimeType present;
};
4. channelCrossing.past.hour = 7;
channelCrossing.past.minute = 12;
channelCrossing.past.second = 44;
channelCrossing.present = now;
5. Interval boatTimes[3];
boatTimes[SWELL_STUFF].present = now; |
|
|
|
|
|
|
|
|
6. A simple struct with four members is sufficient. 7. The primary purpose is to save memory by forcing different values to share the same memory space, one at a time. |
|
|
|
|
|