Question

In c++ Create a function called ​Switch_Them ​that swaps the values of the two inputs; it...

In c++

Create a function called ​Switch_Them ​that swaps the values of the two inputs; it should do so as a pass by reference.

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

C++ code for the above problem-

#include<iostream>

using namespace std;

//call be reference
void Switch_Them(int &a,int &b){
//swapping a and b.
int tmp= a;
a = b;
b = tmp;
}

int main() {

// taking two inputs
int a,b;
cin>>a>>b;

// calling the function by reference to swap the inputs
Switch_Them(a,b);

//displaying the swaped values
cout<<a<<" "<<b;

return 0;
}

Code-

Input and Output-

If the answer helped then please upvote.And for any queries,please comment.

Add a comment
Know the answer?
Add Answer to:
In c++ Create a function called ​Switch_Them ​that swaps the values of the two inputs; it...
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
  • Help answer Questions in C++ 14. Create a function that swaps the values of the two...

    Help answer Questions in C++ 14. Create a function that swaps the values of the two inputs; it should do so as a pass by reference. 15. Create a function that returns the max of two numbers. 16. Create a function that rolls a dice named ROLL. It should create a random number between 1 and 6. Create another function that rolls two dice and says SNAKE EYES if you both rolls are a 1. Call these functions until you...

  • c++ please help Create two arrays of 20 elements, called myArray1 and myArray2 Create a function...

    c++ please help Create two arrays of 20 elements, called myArray1 and myArray2 Create a function randBetween that returns an integer between 2 integer inputs (int randBetween(int min, int max)); Fill the myArray1 with the random values. Loop thru the myArray1 and find the difference between the element i and element i + 1; put that difference in array2 example: array1 = {1, 3, 4, 5} array2 ends up having {-2, -1, -1} Loop thru myArray1 and find the min...

  • Create an application where the user inputs two double values. Pass both variables to a method...

    Create an application where the user inputs two double values. Pass both variables to a method named compucepercent ( that displays the two values and the value of the first number as a percent of the the second one. Then call the method a second time, passing the values in reverse order For example, if the numbers are 2 and 5, a typical output might be 2.0 is 40 percent of 5.0 5 0 is 250 percent of 2.0

  • Write a C++ program that contains a function called swapNums. This function takes two integer parameters,...

    Write a C++ program that contains a function called swapNums. This function takes two integer parameters, swaps them in memory, and outputs the results (there is nothing to return). In main, ask the user to enter two different numbers, output them as entered (step 1), call the function swapNums() which will output the numbers swapped (step 2), and then output the values again in main (step 3). You should have three sets of output. Sample run (10 and 5 were...

  • array function • Create a function called show2D. • This function should accept a two-dimensional array...

    array function • Create a function called show2D. • This function should accept a two-dimensional array as parameter and display its contents that are odd numbers on the screen. • This function should work with any of the following arrays of different sizes: int hours[3][9]; int stamps[7][9]; int cities[15][9]; • Write a demo program to show how to use the function show2D. this is c++ program Task 2: Array functions • Create a function called show2D. • This function should...

  • dev c+ Write the function called simplicity, which makes the denominator and denominator values of the...

    dev c+ Write the function called simplicity, which makes the denominator and denominator values of the simple fraction sent to it as simple as possible, together with a main function where the denominator and denominator information are entered from the keyboard. Print the values of variables that hold the numerator and denominator values entered from the keyboard before sending them to the function and their changed states after they are sent to the screen. (The global variable should not be...

  • Write a proper C program that makes use of a function to accept user inputs and...

    Write a proper C program that makes use of a function to accept user inputs and updates members of a structure. The structure should contain three members: LastName,Gender and Age. LastName will not exceed 30 characters. The structure variable should be created in the main function. The function should be called to populate the structure variable. The assigned values of the members should be appended to a text file in the main function. The input and output should work for...

  • Create a function m-file for the following expression which has two inputs X and Y. Call...

    Create a function m-file for the following expression which has two inputs X and Y. Call it “zoom”. Z = eVX2+Y2 /(X + Y) This function (zoom) can be in a separate script or as the last cell in your main m-file (which includes all of your solutions). Use Zoom to generate values for Z for X and Y values varying from 1 to 4 with an increment of 0.2. Also generate a table that includes all values for X...

  • MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note:...

    MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note: input values are specified in the function call) Output: calculated maximum value Create a row vector A of values from 50 down to 0, with an increment of 0.5 Multiply the elements of A and the square of the elements of the input vector Store the results in B Find the maximum value of B and store it in C – this is the...

  • Because your functions are objects, they can serve as inputs to other functions! Create a new...

    Because your functions are objects, they can serve as inputs to other functions! Create a new function, called "add_or_mult()". This function should take two parameters. The first parameter will be a function. The argument you pass for the parameter will be either your multiply or your add function. The second parameter will be a list, to be used by the function you pass as an argument for the first parameter. Show that you know how to call parameters "out of...

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