1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yanalaym [24]
4 years ago
7

Write a complete C++ program that is made of functions main() and rShift(). The rShift() function must be a function without ret

urn with 6 parameters. rShift() should do following.1)Shift the first 4 formal parameters' value one place to right circularly and send the updated values out to the caller function, i.e. main. Furthermore, after calling this function with first 4 actual parameters, say a1, a2, a3, a4, and these actual parameters should shift their value one place to right circularly as well. That is, a1 takes a2's value, a2 takes a3's value, a3 takes a4's value, and a4 takes a1's value.2)Assuming that first 4 formal parameters of rShift are n1, n2, n3, and n4, rShift should calculate maximum and average of n1, n2, n3, and n4, and send results back to caller function, i.e. main. The main() function should do following:1)Read four integers from the user with proper prompt and save them to four local variables.2)Call the rShift() function with 6 actual parameters.3)Receive all results, i.e. four shifted integers, plus maximum and average from rShift(). Then print these numbers with proper prompt text. Note:•No input and output with the user inside rShift() function. All input and output should be strictly limited inside main() function.•Both statistics must be calculated with basic C++ flow control statements, and cannot be implemented by calling library functions such as max().

Engineering
1 answer:
erma4kov [3.2K]4 years ago
8 0

Answer:

Explanation:

attached is an uploaded picture to support the answer.

the program is written thus;

#include<iostream>

using namespace std;

// function declaration

void rShift(int&, int&, int&, int&, int&, double&);

int main()

{

   // declare the variables

   int a1, a2, a3, a4;

   int maximum = 0;

   double average = 0;

   // inputting the numbers

   cout << "Enter all the 4 integers seperated by space -> ";

   cin >> a1 >> a2 >> a3 >> a4;

   cout << endl << "Value before shift." << endl;

   cout << "a1 = " << a1 << ", a2 = " << a2 << ", a3 = "  

        << a3 << ", a4 = " << a4 << endl << endl;

   // calling rSift()

   // passing the actual parameters

   rShift(a1,a2,a3,a4,maximum,average);

   // printing the values

   cout << "Value after shift." << endl;

   cout << "a1 = " << a1 << ", a2 = " << a2 << ", a3 = "  

           << a3 << ", a4 = " << a4 << endl << endl;

   cout << "Maximum value is: " << maximum << endl;

   cout << "Average is: " << average << endl;

}

// function to right shift the parameters circularly

// and calculate max, average of the numbers

// and return it to main using pass by reference

void rShift(int &n1, int &n2, int &n3, int &n4, int &max, double &avg)

{

   // calculating the max

   max = n1;

   if(n2 > max)

     max = n2;

   if(n3 > max)

     max = n3;

   if(n4 > max)

     max = n4;

   // calculating the average

   avg = (double)(n1+n2+n3+n4)/4;

   // right shifting the numbers circulary

   int temp = n2;

   n2 = n1;

   n1 = n4;

   n4 = n3;

   n3 = temp;

}

You might be interested in
5. Will rotating the tires extend their life?<br><br> O Yes<br> O No
ZanzabumX [31]
Answer is yes.
Tire rotation is undertaken to ensure that the tires wear evenly. This can extend tire life and save you money.
For example, failure to rotate tires on a front-wheel-drive vehicle will eventually result in the front tires having significantly less tread than the rear tires.
5 0
3 years ago
Read 2 more answers
Time management is a learned behavior.<br> True<br> False
larisa [96]

Answer:

true

Explanation:

3 0
3 years ago
Read 2 more answers
What is the best reason a scientist might use a model to represent the solar system?
uranmaximum [27]
So they can grasp a better understanding! good luck
3 0
4 years ago
Which of the following would most likely be operated by a sequential control system?
Rudiy27

Answer:pizza oven

Explanation:

7 0
3 years ago
Read 2 more answers
T he area of a circle is pr 2. Define r as 5, then find the area of a circle,using MATLAB®.(b) The surface area of a sphere is 4
aksik [14]

Answer:

Area of Circle = 78.5398

Surface Area of Sphere =  1.2566 x 10^3 = 1256.6 ft

Volume of Sphere =  33.5103 ft

Explanation:

Please find below the written MatLab script used to solve the problem. I had to define r in each case to solve for the Area of the circle, the surface area and the volume of the Sphere.

r=5; % define r as 5

a=pi*r^2;% calculate the area of the circle

AreaOfCircle=a

r=10; % define r and 10 ft

sa=4*pi*r^2; %Calculate the surface area of the sphere

SphereSurfaceArea=sa

r=2;% define r as 2 ft

vs=(4/3)*pi*r^3;% Calculate the volume of the sphere

VolumeShere=vs

3 0
3 years ago
Read 2 more answers
Other questions:
  • Explain the conductivity results observed for ionic compounds in the solid state and in aqueous solution.i.Solid ionic compounds
    12·1 answer
  • What’s the purpose of current tracks
    6·1 answer
  • A receptacle, plug, or any other electrical device whose design limits the ability of an electrician to come in contact with any
    14·1 answer
  • Suppose you are implementing a relational employee database, where the database is a list of tuples formed by the names, the pho
    14·1 answer
  • What's the difference between a GED and a Diploma?
    12·1 answer
  • Demonstreaza in 20 de propoziti ca snoava pacala si zarzarele boerului e o snoava
    12·1 answer
  • 2. The moist weight of 0.1 ft3 of soil is 12.2 lb. If the moisture content is 12% and the specific gravity of soil solids is 2.7
    6·1 answer
  • A crankcase heater is often used to prevent refrigerant from mixing with compressor oil during periods of:
    11·2 answers
  • Lynx eat snowshoe hares, and snowshoes hears eat plants. Which term can be applied to the lynx in this food chain example? Prima
    10·1 answer
  • Which level of acceleration should you use when accelerating on a short highway entry ramp?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!