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: 3579867 • 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

Program :

#include <iostream> // Header file
using namespace std;
int func(int i, int j, int &k ); // Function definition
main () // main functioon
{
int j = 1; // variable declaration
int k = 2;
for (int i = 1; i <= 5; i += 2) // Loop for function calling
j = func (i, j, k); // caling function
return 0;
}
int func(int i, int j, int &k ) // Called function
{
if (3*i-j/5 > 4) // Check the value satisfied or not
cout << j << " " << i << " " << k++ << endl;
else
cout << j++ << " " << ++i << " " << k++ << endl;
return ++j;
}

Output :

1 2 2

3 3 3

4 5 4

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