Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ For the assignment, we will write a program that uses a function called deleteRepeats that has an array of characters as a formal parameter,

C++ 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 of the corresponding repeated letters from the array. The number of array positions used will be found in a constant aptly named SIZE, and is not being passed as a parameter. The function will return a unique pointer.

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).

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.

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.

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.

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

Students also viewed these Databases questions