Question: Write a program named Reverse.cpp that will display an initialized array of 3 4 doubles on the screen, reverse the order of the array's values,

Write a program named Reverse.cpp that will display an initialized array of 34 doubles on the screen, reverse the order of the array's values, and then display the array again.
Create and use the following functions in your solution:
A function named init() that initialized an array of any length. Initialize an array such that the first half of the elements are equal to the square of their index and the second half of the elements are equal to the square root of their index. To initialize the array, use a single index variable and one or two counter-controlled loops. The function should have two parameters: (1) a reference to the array and (2) a value parameter to get the array's size/length.
A function named display() that displays an array of doubles of any size to the screen. The function should have two parameters: (1) a constant reference to the array and (2) a value parameter to get the array's size/length. The function should display eight elements per line (with a newline at the end of the last lines even though it may not be a full 7 elements). Each displayed value should be rounded to 1 decimal place. The output should be presented in a grid with right-aligned columns of equal width and with a minimum of 2 spaces between the numbers (see the example output below).
A function named swap() that swaps two values in an array of doubles (located at two indexes). The function should accept three parameters: (1) the array, (2) the index of the first element to swap, and (3) the index of the second element to be swapped.
A function named reverse() reverses the order of the values in an array of doubles. The function parameters should include (1) a reference to an array and (2) a copy of the array's size. The values of the array should be actually reversed. Do not put any cout statements within this function. Use a local variable temporary array called tmpArray to do the work of swapping, then copy the results into the parameter array before returning.
Hint: Start by swapping the first and last values in the array. Then, swap the second and next to the last values. Continue until you reach the middle.
Remember that arrays can only be passed by reference. Do NOT use the symbol & when declaring an array as a formal parameter. Any array parameter for a function that does not modify that array should be a constant parameter.
Sample Output (no user input)
The initial values of the array are: 0.01.04.09.016.025.036.049.064.081.0100.0121.0144.0169.0196.0225.0256.04.14.24.44.54.64.74.84.95.05.15.25.35.45.55.65.75.7 The values of the array after reversing them are: 5.75.75.65.55.45.35.25.15.04.94.84.74.64.54.44.24.1256.0225.0196.0169.0144.0121.0100.081.064.049.036.025.016.09.04.01.00.0

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 Programming Questions!