CInt_Vector

Define a class CInt_Vector, whose size can be dyanmically adjusted.
  1. It has a member function init(int n=10), which will allocate an array of n integers from the free storage. If you omit the parameter n when you invoke the init() function, by default it will allocate 40 bytes.
  2. You may call a member function resize(int k) to adjust the size of this array. Imagine that if k is great than the original size n, you have to allocate a new space with 4k bytes, copy the current elements of the array to the new location, and release the old space allocated for the previous smaller array.
  3. This class has a data member m_pData, which points to the starting location of the array.
  4. It also has a data member m_Size, which stores the size of the array. Because m_Size is a private member, you can only retrieve its value via a public member function length().
  5. You can access the element in this array via a function at(). For example, "myVector.at(0) = 3; cout << myVector.at(1);".
  6. Design a member function Print() which will print out the elements in this array. The output may look like this: "[ 1 3 5 7 ]".
  7. (Bonus) Try to overload the "<<" operator so that you can "cout << myVector;" to print out the array.
  8. Please consider what should be done in the constructor. Will it call init() automatically?
  9. What will happen if the programmer calls init() twice? How would you prevent this?
  10. You may also need to define a copy constructor.
  11. What should be done in the destructor?
  12. Write a short main() to test all functions in this class.