Solved:

Checkmark

Answered by AI, Verified by Human Experts

PLEASE HELP

PLEASE HELP6.22 LAB: Swapping variables

Define a function named SwapValues that takes four integers as parameters and swaps the first with the second, and the third with the fourth values. Then write a main program that reads four integers from input, calls function SwapValues() to swap the values, and prints the swapped values on a single line separated with spaces.


Ex: If the input is:


3 8 2 4

function SwapValues() returns and the main program outputs:


8 3 4 2

The program must define and call a function:

void SwapValues(int& userVal1, int& userVal2, int& userVal3, int& userVal4)

Function SwapValues() swaps the values referenced by the parameters.


in c++

Create functionSwapValueswith 4 integer parameters that swaps the 1st with 2nd and 3rd with 4th values. Read and print swapped values.In C++, we can define the function SwapValues() that takes fourinteger parametersas references.The function swaps the first with the second, and the third with the fourth values.We can then write a main program that reads four integers from input, calls theSwapValues() functionpassing in the input integers as arguments, and then prints the swapped values on a single line separated by spaces.Here's how the SwapValues() function can be defined:void SwapValues(int& userVal1, int& userVal2, int& userVal3, int& userVal4) {int temp = userVal1;userVal1 = userVal2;userVal2 = temp;temp = userVal3;userVal3 = userVal4;userVal4 = temp;}And here's themain program:int main() {int num1, num2, num3, num4;cin >> num1 >> num2 >> num3 >> num4;SwapValues(num1, num2, num3, num4);cout << num1 << " " << num2 << " " << num3 << " " << num4 << endl;return 0;}When given the input '3 8 2 4', the program will output '8 3 4 2'.For more such questions onSwapValues:brainly.com/question/28809963#SPJ11...

Unlock full access for 72 hours, watch your grades skyrocket.
For just $0.99 cents, get access to the powerful quizwhiz chrome extension that automatically solves your homework using AI. Subscription renews at $5.99/week.