Question

C++ problem: Write a function that: accepts two integer variable arguments by reference swaps the contents...

C++ problem:

Write a function that:

  • accepts two integer variable arguments by reference
  • swaps the contents of the two variables
  • does not return anything
  • does not interact with the user in anyway

Homework Answers

Answer #1
#include<iostream>

using namespace std;

void swap(int& a, int& b){
   int tmp = a;
   a = b;
   b = tmp;
}

int main() {
   int a,b;
   a=5;
   b=7;
   swap(a,b);
   cout<<"a: "<<a<<endl;
   cout<<"b: "<<b<<endl;
   return 0;
}

void swap(int& a, int& b){
   int tmp = a;
   a = b;
   b = tmp;
}

Know the answer?
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
Similar Questions
C++ problem: Write a function that: accepts three integers as it's only arguments computes the average...
C++ problem: Write a function that: accepts three integers as it's only arguments computes the average of the arguments returns the average without loss of precision does not use global variables does not interact with the user in any way
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in milliseconds. Delay should return a function that, when invoked waits for the specified amount of time before executing. HINT - research setTimeout(); 2.Create a function saveOutput that accepts a function (that will accept one argument), and a string (that will act as a password). saveOutput will then return a function that behaves exactly like the passed-in function, except for when the password string is...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens the file for reading Reads an integer from the file and returns it. Create a main function that Asks the user to input a file Passes that file to the “ReadFile” function Prints the returned integer to the screen Extra Credit: Set a default argument of “intfile.txt” for the “ReadFile” function Write an overloaded function of “ReadFile” that accepts two filenames and reads an...
Write a function that will accept two integer matrices A and B by reference parameters, and...
Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which is equal to M[i][j]. Explain the time complexity of this function inside of the code as a comment.
Write the function definition for a function that requests the user to enter an integer between...
Write the function definition for a function that requests the user to enter an integer between 19 and 47 (both exclusive). Repeat (loop) within the function until a valid number is entered. Return the user’s number using a reference parameter.
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
In C++ 1) Write the function definition that has 1 pass by value integer parameter. The...
In C++ 1) Write the function definition that has 1 pass by value integer parameter. The function contains logic to return true if the parameter is even and false if it is not. 2 ) Write a main function that prompts the user for a value, calls the function that you created in step one with the value entered by the user, display "even" if the function return true and otherwise displays "odd"
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • List and briefly explain each step in the ABCDE technique for examining irrational beliefs that contribute...
    asked 16 minutes ago
  • 1. Find the general solution of the first order linear differential equation: 2*x*dy/dx -y-3/sqrt(x)=0. sqrt() =...
    asked 38 minutes ago
  • Fairfield Homes is developing two parcels near Pigeon Fork, Tennessee. In order to test different advertising...
    asked 43 minutes ago
  • . For each of the following questions, say whether the random process is reasonably a binomial...
    asked 56 minutes ago
  • Please discuss why empathy is so important in light of current events. Please give specific examples
    asked 1 hour ago
  • Describe ONE thing you learned from either Peter singer or Tibor Machan author that compelled you...
    asked 1 hour ago
  • Global logistics firms such as DHL Supply Chain and Global Forwarding or C. H. Robinson Worldwide...
    asked 1 hour ago
  • Please match each factor in adoption of a new product or service to the best match...
    asked 1 hour ago
  • Fatty Acid Synthesis Assignment Explain how the activation of acetyl-CoA carboxylase prevents excess citrate in the...
    asked 1 hour ago
  • 1. Discuss and give an example of how a person might “constructively” enter a building of...
    asked 1 hour ago
  • Define the channel type for a natural trapezoidal dirt channel with a roughness of 0.045. The...
    asked 2 hours ago
  • Petroleum Production Engineering How can flow efficiency being improved without resulting into increasing water production?
    asked 2 hours ago