Question
C++ One problem with dynamic arrays is that once the array is created using the new operator, the size cannot be changed. For example, you
C++
One problem with dynamic arrays is that once the array is created using the new operator, the size cannot be changed. For example, you might want to add or delete entries from the array as you can with a vector. This project asks you to create functions that use dynamic arrays to emulate the behavior of a vector. a. First, write a program that creates a dynamic array of five strings. Store five names of your choice into the dynamic array. b. Next, complete the following two functions:
i. string* addEntry(string *dynamicArray, int &size, string newEntry);
This function should create a new dynamic array one element larger than dynamicArray, copy all elements from dynamicArray into the new array, add the new entry onto the end of the new array, increment size, delete dynamicArray, and return the new dynamic array.
ii. string* deleteEntry(string *dynamicArray, int &size, string entryToDelete);
This function should search dynamicArray for entryToDelete. If not found, the request should be ignored and the unmodified dynamicArray returned. If found, create a new dynamic array one element smaller than dynamicArray. Copy all elements except entryToDelete into the new array, delete dynamicArray, decrement size, and return the new dynamic array.
c. Test your functions by adding and deleting several names to the array while outputting the contents of the array. You will have to assign the array returned by addEntry or deleteEntry back to the dynamic array variable in your main function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started