#include #include #include "array.h" array::array( int size ) { assert( size >= 1 ); numElts = size; assert( (elts = new int [ numElts ]) != NULL ); // remember to set the lower and upper to their proper values here } /* array::array( int low, int high ) { // implement this constructor using the constructor above as a guide } */ array::array( const array& a ) { numElts = a.numElts; assert( (elts = new int [ numElts ]) != NULL ); for ( int i = 0; i < numElts; i++ ) { elts[i] = a.elts[i]; } } array& array::operator =( const array& a ) { if ( this != &a ) { this->array::~array(); } this->array::array(a); return *this; } array::~array() { delete [] elts; } int& array::operator[]( int pos ) { // remember pos is a value indexed from lower to upper, but elts is indexed // from (0...numElts-1) so you need to adjust the array subscript appropriately assert( pos >= 0 && pos < numElts ); return elts[pos]; } int array::numElements() { return numElts; } /* int array::lowerBound() { // uncomment and implement the function to return the lower bound of the array } int array::upperBound() { // uncomment and implement the function to return the upper bound of the array } */ ostream& operator<<( ostream& os, array& a ) { for ( int i = 0; i < a.numElts; i++ ) os << a.elts[i] << " "; return os; }