< previous page page_901 next page >

Page 901
9. The Friends program of Chapter 14 creates an address book with people's names, telephone numbers, and birth dates. A birth date is represented as three separate components of a struct type named EntryType. Modify the Friends program so that friends' birth dates are represented using the DateType class developed in this chapter.
10. Below is the specification of a safe array class, which halts the program if an array index goes out of bounds. (Recall that C++ does not check for out-ofbounds indices when you use built-in arrays.)
const int MAX_SIZE = 200;

class IntArray
{
public:
    int ValueAt( /* in */ int i ) const;
        // Precondition:
        //     i is assigned
        // Postcondition:
        //     IF i >= 0  &&  i < declared size of array
        //         Function value == value of array element
        //                           at index i
        //     ELSE
        //         Program has halted with error message

    void Store( /* in */ int val,
                /* in */ int i   );
        // Precondition:
        //     val and i are assigned
        // Postcondition:
        //     IF i >= 0  &&  i < declared size of array
        //         val is stored in array element i
        //     ELSE
        //         Program has halted with error message

    IntArray( /* in */ int arrSize );
        // Precondition:
        //     arrSize is assigned
        // Postcondition:
        //     IF arrSize >= 1  &&  arrSize <= MAX_SIZE
        //         Array created with all array elements == 0
        //     ELSE
        //         Program has halted with error message
private:
    int arr[MAX_SIZE];
    int size;
};

 
< previous page page_901 next page >