Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 3-Dynamic Arrays and Pointers Modify the container cdlass you wrote for Lab 2 to use pointers and dynamic array allocation. Do not use the

image text in transcribed
Lab 3-Dynamic Arrays and Pointers Modify the container cdlass you wrote for Lab 2 to use pointers and dynamic array allocation. Do not use the [ ] operator to access aray elements, instead use pointer notation. Make the class templated instead of using a typedef statement (see the Bag class from 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: A pointer to the array A variable to hold the current array capacity A variable to keep track of the number 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 10 and num used variable to 0 A one argument constructor dynamically allocates an array of the size passed as an argument and initializes capacity to that number 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 after the copy is complete. The add function will then add the new element to the array Include the following 2 functions A function to remove 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 . Lab 3-Dynamic Arrays and Pointers Modify the container cdlass you wrote for Lab 2 to use pointers and dynamic array allocation. Do not use the [ ] operator to access aray elements, instead use pointer notation. Make the class templated instead of using a typedef statement (see the Bag class from 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: A pointer to the array A variable to hold the current array capacity A variable to keep track of the number 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 10 and num used variable to 0 A one argument constructor dynamically allocates an array of the size passed as an argument and initializes capacity to that number 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 after the copy is complete. The add function will then add the new element to the array Include the following 2 functions A function to remove 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

What is gross output?

Answered: 1 week ago