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

#Program Analysis# – What is output by in the following program? Show All Work #

ID: 3577511 • Letter: #

Question

#Program Analysis# – What is output by in the following program? Show All Work

#include <iostream >

Using namespace std;

int func (int a, int b);

main ()

{

          int j = 3;

                  

          for (int i = 2; i <= 6; i += 2)

          {

                   j = func (i, j);

          }

          return 0;

}

int func (int a, int b)

{

          if (b – a % 3 > 2)

                   cout << “ B   I:   “ << ++a << “   ” << b++ << endl;

          else

                   cout << “ B   II:   “ << a-- << “   ” << --b << endl;

          return a;

}

Output: -

__________________________________________

__________________________________________

__________________________________________

Explanation / Answer

The following program has these outputs may occurs.

Here a value is 2 and b value is 3 then

In first if condition if(b-a % 3>2)

then 3-2 % 3>2 result is 1%3 then 1 then this condition is false

then controll will be going to else part

that is result is 2 2.

Then these process result will be appeara as follows:

2 2

4 2

6 2