Question

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

Write a complete C++ program that is made of functions main() and rShift(). The rShift() function must be a function without return with 6 parameters. rShift() should do following.

  • 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.

  • 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.

  4. Note:

    1. No input and output with the user inside rShift() function. All input and output should be strictly limited inside main() function.

    2. Both statistics must be calculated with basic C++ flow control statements, and cannot be implemented by calling library functions such as max().

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your answer.. Code in C++

#include<iostream>
using namespace std;
//rShift() function be a function without return with 6 parameters
void rShift(int& n1,int& n2,int& n3,int& n4,int& n5,float& n6)
{
//Shifting value
int temp=n4;
n4=n3;
n3=n2;
n2=n1;
n1=temp;
//Computing maximum value
if(n1> n2 && n1>n3 && n1>n4)
n5=n1;
else if(n2> n1 && n2>n3 && n2>n4)
n5=n2;
else if(n3> n1 && n3>n2 && n3>n4)
n5=n3;
else
n5=n4;
//Computing Average value
n6=(n1+n2+n3+n4)/4.0;
}
int main()
{
//n1 n2 n3 n4 are integer will be entered by the user n5 is for max value
int n1,n2,n3,n4,n5;
float n6;//to store average of 4 integer
cout<<"**********************Enter 4 integer value*********"<<endl;
cout<<"Enter value of n1:";
cin>>n1;
cout<<"Enter value of n2:";
cin>>n2;
cout<<"Enter value of n3:";
cin>>n3;
cout<<"Enter value of n4:";
cin>>n4;
rShift(n1,n2,n3,n4,n5,n6);//rShift function call
cout<<"After rShift value of n1:" <<n1<<endl;
cout<<"After rShift value of n2:" <<n2<<endl;
cout<<"After rShift value of n3:" <<n3<<endl;
cout<<"After rShift value of n4:" <<n4<<endl;
cout<<"Max of 4 integer value:"<<n5<<endl;
cout<<"Average of 4 integer value:"<<n6<<endl;
return 0;
}
//Output

Add a comment
Know the answer?
Add Answer to:
Write a complete C++ program that is made of functions main() and rShift(). The rShift() function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that at least consists of the main() function and a recursive...

    Write a complete C++ program that at least consists of the main() function and a recursive function gcd() with return value. Define function gcd() with two and only two parameters that calculates the greatest common divider of two given parameters. Hint: use the difference between two parameters or the remainder obtained using one parameter divide the other. In main() Read 2 positive integers with proper prompt. Call gcd() with proper syntax. Display the result, i.e. the greatest common divider of...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

  • Problem: Create a program that contains two functions: main and a void function to read data...

    Problem: Create a program that contains two functions: main and a void function to read data from a file and process it. Your main function should prompt the user to enter the name of the file (Lab7.txt), store this name, and then call the function sending the name of the file to the function. After the function has completed, the main function should output the total number of values in the file, how many of the values were odd, how...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • I am having trouble with my C++ program.... Directions: In this lab assignment, you are to...

    I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...

  • Please Use C++ for coding . . Note: The order that these functions are listed, do...

    Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • **IN C*** * In this lab, you will write a program with three recursive functions you...

    **IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT