Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Exercise #4: Array Shifting Write a function named shift_right that takes as its arguments the following: a one dimensional array of floating point values;

image text in transcribed C++
Exercise #4: Array Shifting Write a function named "shift_right" that takes as its arguments the following: a one dimensional array of floating point values; an integer, call it N that tells the number of cells in the array. an integer, call it"left", that tells the leftmost cell of the part of the array to be shifted; " an integer, call it "right", that tells the rightmost cell of the part of the array to be shifted; a positive integer, call it "distance" that tells how many cells to shift by The function should make sure that left is less than or equal to right, and that distance is greater than zero. If either of these conditions fails, the function should return the value 1 to indicate an error. Otherwise it should shift by distance cells the content of the array cells with subscripts running from left toright. Thus, for example, if the array passed to the function looks like this: 7 8 9 10 . 5.8 I 2.6 1 9.1 I 3.4 I 7.0 I 5.1 I 8.8 I 0.3 I -4.1 I 8.0 I 2.7 I etc. 3/4 if left has the value 3, right has the value 7, and distance has the value 2, then the function should shift the contents of cells 3,4,5,6, and 7 to the right by 2 cells, so that when the function returns, the aray will have been changed so that it looks like this: 2 10.. 5.81 2.619.1 1 0.00 1 0.00 1341 7.015.1 18.810.3 12.71 etc. The values 0.00 in cells 3 and 4 indicate that we don't care what numbers are in those cells when the function returns (you can put any default values instead). Note that the content of cells 8 and 9 have changed, but the contents of cell 10 is unchanged. The function needs not to take any precautions against the possibility that the cells will be shifted beyond the end of the array (the calling function should be careful not to let that happen right +distance s N). Write a main program that tests and validates the above developed function Sample input/output: lease enter the number of values in the array: 11 lease enter the values for your array: 5.8 2.6 9.1 3.4 7.8 5.1 8.8 e.3 -4.1 8.0 2.7 lease enter the left index, right index, and distance values: 3 7 2 2.6 9.1e 3.4 5.1 8.8.32.7

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

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

What is the yield for the bond? How was this calculated?

Answered: 1 week ago

Question

analyze aesthetic enhancing design rules.

Answered: 1 week ago

Question

How are members held accountable for serving in the assigned roles?

Answered: 1 week ago