< previous page page_1028 next page >

Page 1028
{
   int i;     // Array index

   size = array2.size;
   arr = new int[size];
   if (arr == NULL)
   {
       cout << ** In DynArray copy-constructor, not enough memory
            <<  for  << size <<  elements ** <<  endl;
       exit(1);
   }
   for (i = 0; i < size; i++)
   arr[i] = array2.arr[i];
}

//******************************************************************

DynArray::~DynArray()

// Destructor

// Postcondition:
//      Array pointed to by arr is no longer on the free store

{
    delete [] arr;
}

//******************************************************************

int DynArray::ValueAt( /* in */ int i ) const

// Precondition:
//     i is assigned
// Postcondition:
//     IF i >= 0  &&  i < size
//         Function value == arr[i]
//     ELSE
//         Program has halted with error message

{
  if (i < 0 || i >= size)
  {
      cout < ** In ValueAt function, invalid index: 
           < i < ** < endl;
      exit(1);
}

 
< previous page page_1028 next page >