Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with thissss!! Its a C++ assignment. Function should determine if a letter repeated in the corresponding position of the array and, if

I need help with thissss!! Its a C++ assignment.

Function should determine if a letter repeated in the corresponding position of the array 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, and must be dynamic (placed on the heap). After the work is finished, and the function returns the smart pointer, your program should print the new array 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] = 'a';

noRepeats = deleteRepeats(originalArray);

After this function is executed, the index values would be that the value at [0] is now 'b', the value at [1] is 'c', the value at [2] is 'a', the value at [3] is 'c', the value at [4] is 'a', and the value at [5] is 'c',. (The value of [8-9] and [0-1] are no longer included in the new array since they were corresponding repeats). Also, note that noRepeats is a unique pointer.

You may assume that the partially filled array always contains only lowercase letters.

a) Have the driver (main) program call the function deleteRepeats using the above test array and values. Call the function and use the returned (smart) pointer to display the new array and also display the difference (how many repeats).

b) Create a function called deleteRepeats: this function removes corresponding repeats from the original array that is passed as a parameter (pointer to a c-string), and eventually creates a dynamic array of only the non-repeating corresponding characters. It returns the pointer to that array.

c) Print out the values of the dynamic array and the total number of repeats. If you want to put a separate function together for this, you may encounter issues passing the smart pointer from the driver to the function. One way of passing the smart pointer as an argument is to use the get method. Get will produce a raw pointer and so actually creates a temporary copy, that is, moves the smart pointer to a local. Why is this? B/C 2 instances of a unique pointer cannot manage the same (memory).

Note hereon when we refer to the driver program, we are simply talking about good old main().

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.

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

More Books

Students also viewed these Databases questions

Question

=+What is the relationship between language and human thought?

Answered: 1 week ago

Question

Answer question 13. Need full explanation and details.

Answered: 1 week ago