Question

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

Program: 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.

  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 the 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 the 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().
0 0
Add a comment Improve this question Transcribed image text
Answer #1
C++ Program
#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;
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Program: Write a complete C++ program that is made of functions main() and rShift(). The rShift()...
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 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...

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

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

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

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

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

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