The program ends the first time that the user chooses not


First, write a function deleteFromArray which receives three arguments in its parameters: an array of integers; an offset indicating a position in the array; and an integer containing the size of the array.

The function then deletes the value at the position indicated by the offset (by shifting all values to the right of the deleted value one offset to the left), and finally returns the new size of the array.

Next, write a program to use this function. Particularly, the program first sets, declares, and initializes an array as follows: int myValues[10] = {0,1,1,2,3,5,8,13,21,34}; int arraySize = 10; Next, the program repeatedly displays the array to the user, asking whether they wish for a something to be deleted. If the user responds in affirmative, the program asks them for the offset in the array of the value to be deleted.

It then calls your deleteFromArray function to carry out the actual deletion, receiving the new size of the array from the function. If the user asks to delete from an offset that goes beyond the end of the array, an appropriate message is displayed stating that the deletion cannot be carried out.

The program ends the first time that the user chooses not to delete a value from the array. Your main function may also call other functions to carry out some of its work. Here is an example execution of the required program (input typed by the user is in green).

The formatting of your program's output should match this example. Array: {0,1,1,2,3,5,8,13,21,34} Want to delete something? (y/n) y Offset to delete? 3 Array: {0,1,1,3,5,8,13,21,34} Want to delete something? (y/n) y Offset to delete? 7 Array: {0,1,1,3,5,8,13,34} Want to delete something? (y/n) y Offset to delete? 9 Sorry, can't delete that.

Want to delete something? (y/n) n Goodbye!

Carefully note the following in the example output above: The user first asks for deletion at offset 3, which refers to the value 2 in the array. Every value to the right of the 2 in the original array must be consequently copied one position to the left.

For example, value 8 was at offset 6 before the first deletion (we deleted value 2, remember?), but appears at offset 5 (one left of its previous location) after the deletion. Also note that 10 elements were displayed before the first deletion, but 9 elements are displayed after it.

To get this right, you need to keep track of the number of elements in the array, as well as the array itself. Also note that when the user tries to delete the item at offset 9 after the two deletions, when there were only 8 valid elements remaining in the array, the program declines to carry out the deletion.

Solution Preview :

Prepared by a verified Expert
Programming Languages: The program ends the first time that the user chooses not
Reference No:- TGS01528594

Now Priced at $10 (50% Discount)

Recommended (92%)

Rated (4.4/5)