Question: C++ language What is the output from the following program fragment? You may assume it is part of a complete, correct C++ program. int mystery(

C++ language

What is the output from the following program fragment? You may assume it is part of a complete, correct C++ program.

int mystery( int a, int b )

{

int c = a + b;

b = a + c;

a += c + b;

cout << "a = " << a << " b = " << b << " c = " << c << endl;

return a + b + c;

}

int main()

{

int a = 2, b = 5, c;

c = mystery( b, a );

cout << "a = " << a << " b = " << b << " c = " << c << endl;

b = mystery( a, c );

cout << "a = " << a << " b = " << b << " c = " << c << endl;

return 0;

}

Now, again with the following change to the function mystery():

int mystery( int &a, int b )

Now, again with the following change to the function mystery():

int mystery( int a, int &b )

Now, again with the following change to the function mystery():

int mystery( int &a, int &b )

For reference, here is the code again:

int mystery( int a, int b )

{

int c = a + b;

b = a + c;

a += c + b;

cout << "a = " << a << " b = " << b << " c = " << c << endl;

return a + b + c;

}

int main()

{

int a = 2, b = 5, c;

c = mystery( b, a );

cout << "a = " << a << " b = " << b << " c = " << c << endl;

b = mystery( a, c );

cout << "a = " << a << " b = " << b << " c = " << c << endl;

return 0;

}

Have functions mystery1() and main1(), mystery2(), main2(), etc. through 3 and 4. Call main1(), 2, 3 and 4 from main(). Do not write all the mystery() calls directly from main().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!