//******************************************************************
// SPECIFICATION FILE (dynarray.h)
// This file gives the specification of an integer array class
// that allows:
// 1. Run-time specification of array size
// 2. Trapping of invalid array indexes
// 3. Aggregate copying of one array to another
// 4. Aggregate array initialization (for parameter passing by
// value, function value return, and initialization in a
// declaration)
//******************************************************************
class DynArray
{
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
void CopyFrom( /* in */ DynArray array2 );
// Postcondition:
// IF there is enough memory for a deep copy of array2
// This object is a copy of array2 (deep copy)
// ELSE
// Program has halted with error message
DynArray( /* in */ int arrSize );
// Constructor
// Precondition:
// arrSize is assigned
// Postcondition:
// IF arrSize >= 1 && There is enough memory
// Array of size arrSize is created with all
// array elements == 0
// ELSE
// Program has halted with error message
DynArray( const DynArray& array2 );
// Copy-constructor
// Postcondition:
// IF there is enough memory
// New array is created with size and contents
// the same as array2 (deep copy)
// ELSE
// Program has halted with error message
// Note:
// This constructor is implicitly invoked whenever a
// DynArray object is passed by value, is returned as
// a function value, or is initialized by another
// DynArray object in a declaration
~DynArray();
// Destructor
// Postcondition:
// Array is destroyed
private:
int* arr;
int size;
};