// p249.txt - Tests the LongArray class. #include #include #include // for set_new_handler() #include "long.h" void arraysize_error() { cout << "Array too large. Aborting program.\n"; exit(1); } int main() { set_new_handler( arraysize_error ); const unsigned ArraySize = 20; LongArray L(ArraySize, 0xFFFF ); unsigned i; cout << "Initialized with default values:\n"; for(i = 0; i < L.GetSize(); i++) cout << L.Get(i) << ','; cout << "\n----------------------------------\n"; for(i = 0; i < L.GetSize(); i++) L.Put(i, rand()); cout << "Initialized with random values:\n"; for(i = 0; i < L.GetSize(); i++) cout << L.Get(i) << ','; cout << "\n----------------------------------\n"; LongArray Z( L ); // copy constructor cout << "After copying the array:\n"; for(i = 0; i < Z.GetSize(); i++) cout << Z.Get(i) << ','; cout << "\n----------------------------------\n"; const unsigned GrowValue = 5; Z.GrowBy( GrowValue ); Z.Put( 0, 9999 ); cout << "After expanding by 5 and changing elt(0):\n"; for(i = 0; i < Z.GetSize(); i++) cout << Z.Get(i) << ','; return 0; }