Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions