Question: In C++ please. For the assignment, we will write a program that uses a function called deleteRepeats that has an array of characters as a
In C++ please.
For the assignment, we will 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.
You may assume that the partially filled array always contains only lowercase letters.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
