Using C++ , write a main method to: 1.) Sets up two values in main, a and b. 2.)
ID: 3675699 • Letter: U
Question
Using C++, write a main method to: 1.) Sets up two values in main, a and b. 2.) read in two variables using a Read function 3.) print the two variable using a Print function 4.) switch the data in the two variables, using a Swap function 5.) print the two variables again using the Print function. Read Function – pass by reference Code a function that reads in two variables. Print Function – pass by value Code a function that prints out two variables with documentation, such as: “The first value is “ ______ “The second value is “______ Swap Function – pass by reference Code a function that will switch the values of two memory positions in main Main Function Code a main method/function that will accomplish the 4 steps given above.
Explanation / Answer
#include<iostream.h>
using namespace std;
int a,b;
void MyRead()
{
cout << "Enter two numbers ";
cin >> a >> b;
}
void print()
{
cout <<"Value of a is: " << a << endl;
cout <<"Value of b is: " << b << endl;
}
void main()
{
int a,b;
MyRead();
MyPrint();
void swap(int a,int b);
int x=10,y=20;cout<<" Two Numbers are a and b: "<<x<<" & "<<y<<". They are to be swapped";
swap(x,y);
}
void swap(int a,int b)
{
a=a+b;
b=a-b;
a=a-b;
cout<<" After swapping: a="<<a<<" & b="<<b;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.