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

Determine what would be outputted to the screen from the following code. (20 Poi

ID: 3570131 • Letter: D

Question

Determine what would be outputted to the screen from the following code. (20 Points)

        int j = 12;

                int n = 7;

do {

cout << " counting " << j;

j+=3;

n++;

} while(j < 16);

cout << " n:" << n;

                void m(int & number, const int numbers[])

                {

                        number = 1001;

                numbers[0] = 5555;

                }

        int main()

        {

                        int x = 1;

                        int y[10];

                y[0] = 1;

                        m(x, y);

                        cout <<

Explanation / Answer

The complete code provides error messages. Since, it is mentioned as one code.

The codes that are provided are properly modified and the proper programing design is given to the code as shown below. Since there are three programs in the code, so the outputs are provided accordingly.

a)

The proper programing format of the first code is given as:

int main()

{

     int j = 12;

     int n = 7;

     do

     {

          cout << " counting " << j;

          j+=3;

          n++;

     } while(j < 16);

     cout << " n:" << n<<endl;

     system("pause");

     return 0;

}

In the first iteration j=12 and n=7. Hence, value of j=12 is printed. The value of j is incremented by 3 and n is incremented by 1. The condition is true now. Iteration continues.

In the second iteration, j=15 and n=8. Hence, value of j=15 is printed. The values of j and n are incremented by 3 and 1 respectively. The condition fails.

The loop is terminated. The present values of j and n are 18 and 9.

Therefore, n value is printed as 9.

Sample output:

counting 12

counting 15

n:9

------------------------------------------------------------------------------------------------------------------

b)

The proper programing format of the second code is given as:

#include "StdAfx.h"

#include <iostream>

using namespace std;

void m(int & number, int *numbers)

{

     number = 1001;

     numbers[0] = 5555;

}

int main()

{

     int x = 1;

     int y[10];

     y[0] = 1;

     m(x, y);

     cout << "x is " << x << endl;

     cout << "y[0] is " << y[0] << endl;

     system("pause");

     return 0;

}

In the above code, the variable x is assigned with value 1 and y[0] with value 1.

In the next step m() function is called by passing the references of the variables x and y[0].

In the m function the x value is modified to 1001 and y[0] is modified to 5555.

Hence, the output is as given below:

Sample output:

x is 1001

y[0] is 5555

------------------------------------------------------------------------------------------------

c)

The proper programing format of the third code is given as:

int main()

{

     int g = 45;

     int j;

     cout << "g: " << g << endl;

     if(g >= 70)

          cout << "at cutoff" << endl;

     cout << "g is at least 70" << endl;

     cout << "g: " << g << endl;

     if(g = 1)

          cout << "you get one" << endl;

     cout << "g: " << g << endl;

     for(j = 12; j <= 25; j = j+3)

     {

          cout << j << " ";

     }

     cout<<endl;

     system("pause");

     return 0;

}

Sample output:

g: 45

g is at least 70

g: 45

you get one

g: 1

12 15 18 21 24

Press any key to continue . . .

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