#include using namespace std; //This class does some dynamic array handling class ArrayHandler { public: ArrayHandler(int s); ~ArrayHandler(); int Get(int loc); void Set(int val, int pos); int ChangeSize(int s); private: int **theArray; int size; }; int main() { int arraySize = 10; ArrayHandler handler(arraySize); //Sets the values for the entire array for (int i = 0; i < arraySize; ++i) { handler.Set(i, i); } //Prints the array for (int i = 0; i < arraySize; ++i) { cout << "theArray[i] = " << handler.Get(i) << endl; } arraySize = 8; handler.ChangeSize(arraySize); //Sets the value of the last element of the array handler.Set(100, arraySize); for (int i = 0; i < arraySize; ++i) { cout << "theArray[i] = " << handler.Get(i) << endl; } return 0; } //Creates an array of size s and initializes all values to zero ArrayHandler::ArrayHandler(int s) { size = s; theArray = new int*[size]; for (int i = 0; i < size; ++i) { theArray[i] = 0; } } //Clean up memory ArrayHandler::~ArrayHandler() { delete [] theArray; } //Gets the value of the array element at position loc int ArrayHandler::Get(int loc) { return *(theArray[loc]); } //Sets the array element at position pos to the value of val void ArrayHandler::Set(int val, int pos) { int temp = val; theArray[pos] = &temp; } //Changes the size of the internal array to size s //Keeps the old values or sets new elements to 0 as appropriate int ArrayHandler::ChangeSize(int s) { int **tempArray = new int*[s]; for (int i = 0; i < size; ++i) { tempArray[i] = theArray[i]; } for (int i = size; i < s; ++i) { tempArray[i] = 0; } size = s; delete [] theArray; theArray = tempArray; }