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

Question (1) Write the definition of a function named rotate4ints that is passed

ID: 3816739 • Letter: Q

Question

Question (1)

Write the definition of a function named rotate4ints that is passed four int variables . The function returns nothing but rotates the values of the four variables : the first variable , gets the value of the last of the four, the second gets the value of the first, the third the value of the second, and the last (fourth) variable gets the value of the third. So, if i, j, k, and m have (respectively) the values 15, 47, 6 and 23, and the invocation rotate4ints(i,j,k,m) is made, then upon return, the values of i, j, k, and m will be 23, 15, 47 and 6 respectively.

———————————

Question (2)

Write the definition of a function named maxmin that is passed four int arguments . The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the the smaller of the first two arguments in its fourth argument . So, if you invoke maxmin(3,7,x,y), upon return x will have the value 7 and y will have the value 3

————————————

Question (3)

Assume that a function named swapdoubles has been defined and is available for use in this exercise: that function receives two variables of type double and exchanges their values . Write the definition of a function named sort3 that is passed three double variables . The function returns nothing but modifies the values of these variables so they are in sorted order. So, if a, b and c have (respectively) the values 3.14, 2.71, and 3.04, and the invocation sort3(a,b,c) is made, then upon return, the values of a, b and c will be 2.71, 3.04, and 3.14 respectively.

————————————

Question (4)

Given an integer variable i, declare a reference variable r that is a reference to i

Explanation / Answer

Solution for Question 2

b) if you invoke maxmin(3,7,x,y), upon return x will have the value 7 and y will have the value 3

}

So, it outputs the maximum number in third variable X and minimum value in fourth i.e. Y.

Solution for Question 3

c) if a, b and c have (respectively) the values 3.14, 2.71, and 3.04, and the invocation sort3(a,b,c) is made, then upon return, the values of a, b and c will be 2.71, 3.04, and 3.14 respectively.

Use Swapdoubles() function

void sort3 (double &a, double &b, double &c){
if (a>b) swapdoubles (a,b);

if (b>c) swapdoubles (b,c);

if (a>b) swapdoubles (a,b);
}

Solution of Question 4

d) Given an integer variable i, declare a reference variable r that is a reference to i

int&r = i;

  # include <iostream>  using namespace std;    void maxmin (int, int, int&, int&);    int main ()  {      int a, b, x, y;      cin >> a >> b >> x >> y;      maxmin(a,b,x,y);      cout << a << b << x << y;        }    void maxmin ( int a, int b, int &x, int &y)  {          if (a > b)          {                  x = a;                  y = b;          }          else          {                  y = a;                  x = b;          }  

}

So, it outputs the maximum number in third variable X and minimum value in fourth i.e. Y.

Solution for Question 3

c) if a, b and c have (respectively) the values 3.14, 2.71, and 3.04, and the invocation sort3(a,b,c) is made, then upon return, the values of a, b and c will be 2.71, 3.04, and 3.14 respectively.

Use Swapdoubles() function

void sort3 (double &a, double &b, double &c){
if (a>b) swapdoubles (a,b);

if (b>c) swapdoubles (b,c);

if (a>b) swapdoubles (a,b);
}

Solution of Question 4

d) Given an integer variable i, declare a reference variable r that is a reference to i

int&r = i;