/******************************************************************** Author: Dana Vrajitoru, IUSB, CS Class: C243, Spring 2012 File name: my_array.cc Last updated: January 10, 2012. Description: Implementation of a class that implements a safe array. *********************************************************************/ #include "my_array.h" #include using namespace std; #include // Constructor with given size, can be used as default constructor. My_array::My_array(int the_size) { array = NULL; size = 0; resize(the_size); } // Destructor. If the array is not empty, it must be deallocated. My_array::~My_array() { empty(); } // Copy constructor My_array::My_array(My_array &data) : size(data.size) { array = new int[size]; for (int i=0; i= 0) { empty(); if (the_size != 0) { size = the_size; array = new int[size]; } } else cout << "Resize attepmted with a negative size. " << "Operation ignored." << endl; } // Access an element of the array. If the index (subscript) is out // of the array, it prints an error message and exits the program. int &My_array::operator[](int index) { if (index >= 0 && index < size) return array[index]; else { cerr << "Illegal access to an element of the array." << endl << "The size of the array was " << size << " and the index was " << index << endl; exit(1); } } // Returns the size of the array. int My_array::get_size() { return size; } // Output the elements of the array. void My_array::output() { cout << "The array of size " << size << " contains the elements:" << endl; for (int i=0; i