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

Problem 1 - 3. What is printed by the function func() in the following program?

ID: 3579176 • Letter: P

Question

Problem 1 - 3. What is printed by the function func() in the following program? Show All Work!

// Final.cpp

#include <iostream.h>

int func(int i, int j, int &k );

main ()

{

                    int j = 1;

                    int k = 2;

                   

                    for (int i = 1; i <= 5; i += 2)

                    j = func (i, j, k);

                    return 0;

}

int func(int i, int j, int &k )

{

                    if (3*i-j/5 > 4)

                                         cout << j << " " << i << " " << k++ << endl;

                    else

                                         cout << j++ << " " << ++i << " " << k++ << endl;

                    return ++j;

}

Problem 1. ______________

Problem 2. ______________

Problem 3. ______________

Explanation / Answer

Before Iteration(i): 1 -> j: 1
Calling func( 1, 1, 2 )
For i = 1, Inside func, value of i, j, and k:
1 2 2
Ater Iteration(i): 1 -> j: 3


Before Iteration(i): 3 -> j: 3
Calling func( 3, 3, 3 )
For i = 3, Inside func, value of i, j, and k:
3 3 3
Ater Iteration(i): 3 -> j: 4


Before Iteration(i): 5 -> j: 4
Calling func( 5, 4, 4 )
For i = 5, Inside func, value of i, j, and k:
4 5 4
Ater Iteration(i): 5 -> j: 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote