Objective:
Program with a class template
Preparation:
Review Section 16.4 from Starting Out with C++ by Gaddis.
Programming:
- Name the files LlllFfffarray.h and LlllFfffLab13.cpp where Llll is the first four letters of your last name and Ffff is the first four letters of your first name. Remember, for a class template the
implementations of the member function templates should be in the .h file.
- Create a class template Array. The class template will use dynamically allocated storage for the data. Therefore
a destructor will be necessary to deallocate dynamic memory. This template will be
similar to the vector template. Provide two constructors to support the following two instantiations: Array<type> data; and Array<type> data(n); where n is an integer value specifying how many elements to store. Provide a member function
to add a new element to the end of the array and a member function to remove the last
element from the array. Provide a member function (similar to the at member function
of the vector template) or overload the subscript operator to allow access to an existing
element within the array.
- Write a driver to test the class template by creating an Array of strings. The driver should allow the user to specify the initial size for the
Array and allow the user to input the initial values to store in the array. Then it should
also allow the user to add and/or remove elements at the end. Finally, it should display
the contents of the array object. It should be menu-driven using a loop to let the
user pick add, remove, display, or quit. Be sure to pass any template class objects
by reference since we are not providing a deep copy constructor.
- Verify your program works correctly.
- Submit your source code file to garth.sorenson@snow.edu. Due at 8:00 am on 7 April.