Question: Modify the container class you wrote for Lab 2 to use pointers and dynamic array allocation. Do not use the [ ]operator to access array

 Modify the container class you wrote for Lab 2 to use

Modify the container class you wrote for Lab 2 to use pointers and dynamic array allocation. Do not use the [ ]operator to access array clements, instead use pointer notation Make the class templated instead of using a typedef statement (sce the Bag class fronm Chapter 3). You may use one file for your template class instead of breaking it into 2 files. Test with an array of strings Your class should include the following data members: Apointer to the array A variable to hold the current array capacity . A variable to koep track of the umber of elements currently being used Include 2 constructors (or you can write one constructor with a default value for size): The default constructor dynamically allocates an array of size 10 and initializes capacity to A one argument constructor dynamically allocates an array of the sine passed as an argument and initializes capacity to that number and num used variable to 0. 10 and num used variable to 0, . Include a destructor that will release the allocated memory Include a function to add a given element to the array at the next available location by including the following feature: If the array has reached its capacity, the add function should call a helper function to double the size of the array. The helper function will dynamically allocate storage for an array of twice the size, copy all the elements in the original array and update all the data members. The original pointer to the array should point to this new storage area afler the copy is complete. The add function will then add the new element to the array. Include the following 2 functions A function to remeve an element at a given location (remaining elements should be rearranged so that there are no "holes" in the array). .A function to add an element at a given location (initial elements must be moved to make room for the new clement)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!