< previous page page_1024 next page >

Page 1024
fice to create a class object, use the ValueAt function to output the array elements, and verify that the elements are all zero:
DynArray testArr(50);

for (index = 0; index << 50; index++)
    cout << testArr.ValueAt(index) << endl;
Regarding the class destructor, there is nothing to test. The function simply deallocates the dynamic array from the free store.
The ValueAt and Store functions: The essence of each of these functions is simple: the Store function stores a value into the array, and ValueAt retrieves a value. Additionally, the function postconditions require each function to halt the program if the index is out of bounds.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
ValueAt (In: i)
Out: Function value
IF i << 0 OR i > size
    Print error message
    Halt the program
Return arr[i]

Store (In: val, i)
IF i << 0 OR i > size
    Print error message
    Halt the program
Set arr[i] = val

Testing: To test these functions, valid indices (0 through size-1) as well as invalid indices should be passed as parameters. Programming Warm-Up Exercises 11 and 12 ask you to design test data for these functions and to write drivers that do the testing.

 
< previous page page_1024 next page >