Consider the following program. What is its exact output? (C++) #include <iostre
ID: 3772195 • Letter: C
Question
Consider the following program. What is its exact output? (C++)
#include <iostrem>
using namespace std;
void funOne(int& a, int b);
int main ()
{
int num1, num2;
num1 = 10;
num2 = 20;
cout<<”In main: num1 = “<<num1<<”num2 = “<<num2<<endl;
funOne(num1, num2);
cout<<”In main after funOne: num = “<<num1<<”num2 = “<<num2<<endl;
return 0;
}
void funcOne(int& a, int b)
{
int x = 12;
b=b+x;
x=x+5;
a=a+x;
cout<<”In funOne: a = “<<a<<”x = “<<x<<”b= “<<b<<endl;
}
Explanation / Answer
Output:
In main: num1 = 10num2 = 20
In funOne: a = 27x = 17b= 32
In main after funOne: num = 27num2 = 20
There are errors in your code, use modified code of yours to get correct which is given below:
Program:
//Change the library to iostream
#include <iostream>
using namespace std;
void funOne(int& a, int b);
int main ()
{
int num1, num2;
num1 = 10;
num2 = 20;
cout<<"In main: num1 = "<<num1<<"num2 = "<<num2<<endl;
//call the function
funOne(num1, num2);
cout<<"In main after funOne: num = "<<num1<<"num2 = "<<num2<<endl;
return 0;
}
void funOne(int& a, int b) //Chaged funcOne to funOne.
{
int x = 12;
b=b+x;
x=x+5;
a=a+x;
cout<<"In funOne: a = "<<a<<"x = "<<x<<"b= "<<b<<endl;
}
Reasons for errors in your code:
You mistyed #include<iostream> as #include<strem>" there is no library in c++ with name strem. So change first line in your code to #include<iostream>
The double used in your code are not supported by c++.Change your double and use double used in modified code given to you.
Change the name 'funcOne' to 'funOne' while defining the function. because name of function used to call, and the name of the function used during defining function are different.