Question
Write a program that uses a function called deleteRepeats that has an array of characters as a formal parameter, and that deletes all repeated letters
Write a program that uses a function called deleteRepeats that has an array of characters as a formal parameter, and that deletes all repeated letters from the array. The number of array positions used will be found in a constant aptly named SIZE, and it will not be passed as a parameter. The function will return a unique pointer.
The function should determine if a letter repeated and, if so, that letter is deleted. You should write the non-repeats to a new dynamic array. The remaining letters will form the new array and the size will be exactly that of the remaining unique letters.
So the new, dynamic array is a result of the deletion activities (i.e., holds just the unique elements). This array is must be created using a smart (unique) pointer. After the work is finished, the function will return the smart pointer and your program should print the new array using that smart pointer and report the difference. This can be done in the driver program (no additional function needed). Consider using a range based for loop and perhaps have an ongoing count too.
Include this test case as part of your driver code:
char originalArray[SIZE];
originalArray [0] = 'a';
originalArray [1] = 'b';
originalArray [2] = 'b';
originalArray [3] = 'c';
originalArray [4] = 'a';
originalArray [5] = 'c';
originalArray [6] = 'a';
originalArray [7] = 'c';
originalArray [8] = 'b';
originalArray [9] = 'c';
noRepeats = deleteRepeats(originalArray);
After this function is executed, the index values would be that the value at [0] is 'a', the value at [1] is 'b', and the value at [2] is 'c'. (The value of [3-9] is no longer of any concern, since the array no longer uses these indexed variables). Also, notice that noRepeats is a unique pointer.
TECHNICAL NOTES:
Returns a (unique) pointer to a heap array that this program takes ownership of.
Program acquires ownership of a uniquely-owned array with dynamic lifetime from the deleteRepeats function.
The use of std::unique_ptr for this program is mainly of intellectual interest.
Your output should look similar to this:
New Array: Amount of characters deleted: 7 Process returned 0 (Oxo) execution time 8.228 s Press any key to continue
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