Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function named \"shiftRight\" that takes as its arguments the following:

ID: 3568430 • Letter: W

Question

Write   a   function   named   "shiftRight"   that   takes   as   its   arguments   the   following:
(1)   an   array   of   floating   point   values (double   type);
(2)   an   integer   that   tells   the   number   of   cells   in   the   array   (its   size/capacity).
The   function   should   shift   the   contents   of   each   cell   one   place   to   the   right,   except   for   the   contents  
of   the   last   cell,   which   should   be   moved   into   the   cell   with   index   0.  
Thus,   for   example,   if   the   array   passed   to   the   function   looks   like   this:
       0                       1                       2                       3                           4
5.8   |   2.6   |   9.1   |   3.4   |   7.0  
then   after   the   call   to   the   function   is   made   from   main(),   the   array   will   have   been   changed   so   that   it  
looks   like   this:
0 1 2 3 4
7.0   |   5.8   |   2.6   |   9.1   |   3.4
IMPORTANT!   The   function   should   NOT return   a   value.

Explanation / Answer

void shiftRight(double array[], int size){
    double temp = array[size-1];
   for(int i=size-1; i>=1; i--)
   array[i] = array[i-1];
   array[0] = temp;
}

// TEST PROGRAM.

#include <iostream>
using namespace std;
// Write   a   function   named   "shiftRight"   that   takes   as   its   arguments   the   following:
// (1)   an   array   of   floating   point   values (double   type);
// (2)   an   integer   that   tells   the   number   of   cells   in   the   array   (its   size/capacity).

void shiftRight(double array[], int size){
    double temp = array[size-1];
   for(int i=size-1; i>=1; i--)
   array[i] = array[i-1];
   array[0] = temp;
}
int main()
{
double a[]={5.8 , 2.6, 9.1, 3.4 , 7.0 };
shiftRight(a,5);
for(int i=0; i<5; i++)
cout << a[i] << " ";

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote