Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

11. What is the output of the following program fragment: void find(int a, int&

ID: 3629295 • Letter: 1

Question

11. What is the output of the following program fragment:

void find(int a, int& b, int& c)
{
int temp;
c = a + b;
temp = a;
a = b;
b = 2 * temp;
}

int main()
{
int x, y, z;

x = 15;
y = 25;
z = 30;

find(x, y, z);
cout << x << " " << y << " " << z << endl;
find(y, x, z);
cout << x << " " << y << " " << z << endl;
find(z, y, x);
cout << x << " " << y << " " << z << endl;
}

12. Write a C++ function which initializes its three reference parameters. The function should take an int, double, and string parameter and initialize them to 0 and the empty string ("").

Explanation / Answer

11. void find(int a, int& b, int& c)
{
int temp;
c = a + b;
temp = a;
a = b;
b = 2 * temp;
}

int main()
{
int x, y, z;

x = 15;
y = 25;
z = 30;

find(x, y, z);
cout << x << " " << y << " " << z << endl;
find(y, x, z);
cout << x << " " << y << " " << z << endl;
find(z, y, x);
cout << x << " " << y << " " << z << endl;
}
15 30 40
60 30 45
75 90 45

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote