Question: Practice C++. Write a program that replaces the numbers of an arrangement according to the following instructions: Write a function called readElelements where you ask

Practice C++.

Write a program that replaces the numbers of an arrangement according to the following instructions:

Write a function called readElelements where you ask the user for the size of the array and the integer elements that the array will contain.

Add a function called replaceElements that replaces each element except the first and last by the larger of its two neighbors. The function should take two parameters: An integer array, and the length of the given array.

Add a function called movesCount that returns the number of elements that were replaced in the final array.

Add a function called displayResults that shows the output according to the following:

Output: Examples

Original: {1, 5} Final: {1, 5} Moves: 0

Original: {1} Final: {1} Moves: 0

Original: {1, 3, 5} Final: {1, 5, 5} Moves: 1

Original: {5, 3, 1} Final: {5, 5, 1} Moves: 1

Original: {1, 2, 3, 4, 5} Final: {1, 3, 4, 5, 5} Moves: 3

Original: {5, 4, 3, 2, 1} Final: {5, 5, 4, 3, 1} Moves: 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!