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

HELP PLEASE Briefly describe the output of each small C++ program below. The out

ID: 3799589 • Letter: H

Question

HELP PLEASE

Briefly describe the output of each small C++ program below. The output must be exact – be especially careful regarding the type of data returned. (is in an integer? Is it a floating point number?)

Note: pay close attention to (d) and (f).

(a)

int x = 3;

int y = 4;

int x = 4;

cout << x;

(b)

int x = 4;

while (x < 5)

    x = x + 1;

cout << x << endl;

(c)

int x = 3;

double y = 3.0;

if (x <= y)

     x = x + 2;

cout << x << endl;

(d)

int tc = 0;

int tf = 0;

tf = (9/5) * tc + 32;

cout << tf << endl;

(e)

int x = 0;

while (x < 6) {

if ((x % 2) == 0)

    cout << "even: " << x << endl;       

else

    {

    cout << "odd: " << x << endl;

    }

x = x + 1;

}

(f)

int x = 1;

int i = 0;

while (x <= 4) {

    x = x * i;

    i = i + 1;

    cout << x << endl;

}

(g)

double multiply1(int num1, int num2 = 1, int num3 = 0);

int main () {

int number1 = 10;

int number2 = 10;

cout << multiply1(number1, number2) << endl;

return 0;

}

double multiply1(int num1, int num2, int num3) {

return num1*num2*num3;

}

(a)

int x = 3;

int y = 4;

int x = 4;

cout << x;

(b)

int x = 4;

while (x < 5)

    x = x + 1;

cout << x << endl;

(c)

int x = 3;

double y = 3.0;

if (x <= y)

     x = x + 2;

cout << x << endl;

(d)

int tc = 0;

int tf = 0;

tf = (9/5) * tc + 32;

cout << tf << endl;

(e)

int x = 0;

while (x < 6) {

if ((x % 2) == 0)

    cout << "even: " << x << endl;       

else

    {

    cout << "odd: " << x << endl;

    }

x = x + 1;

}

(f)

int x = 1;

int i = 0;

while (x <= 4) {

    x = x * i;

    i = i + 1;

    cout << x << endl;

}

(g)

double multiply1(int num1, int num2 = 1, int num3 = 0);

int main () {

int number1 = 10;

int number2 = 10;

cout << multiply1(number1, number2) << endl;

return 0;

}

double multiply1(int num1, int num2, int num3) {

return num1*num2*num3;

}

Explanation / Answer

Question a:

int x = 3;

int y = 4;

int x = 4;

cout << x;

Output:

4

// only the last value assigned is initialize to x

Question b:

int x = 4;
while (x < 5)
x = x + 1;
cout << x << endl;

Output: 5

while loop loops until x reaches 5

Question c:

int x = 3;
double y = 3.0;
if (x <= y)
x = x + 2;
cout << x << endl;

Output : 5

here x is an integer. x and y are equal in if condition so the x incremented by 2

Question d:

int tc = 0;
int tf = 0;
tf = (9/5) * tc + 32;
cout << tf << endl;

Output: 32

Here tf is integer. tf = 1 * 0 +32 = 32

Question e:

int x = 0;
while (x < 6) {
if ((x % 2) == 0)
cout << "even: " << x << endl;   
else
{
cout << "odd: " << x << endl;
}
x = x + 1;
}

Output :

even: 0
odd: 1   
even: 2
odd: 3   
even: 4
odd: 5

//here it prints even or odd based on index value

Question f:

int x = 1;
int i = 0;
while (x <= 4) {
x = x * i;
i = i + 1;
cout << x << endl;
}

Output:

0

0

0

0

0

.

.

// it is a never ending loop with contiuesly prints 0's

why x is multiply with 0 so what even the values will be the result of x is always zero

Question g:

double multiply1(int num1, int num2 = 1, int num3 = 0);

int main () {
int number1 = 10;
int number2 = 10;
cout << multiply1(number1, number2) << endl;


return 0;
}

double multiply1(int num1, int num2, int num3) {
return num1*num2*num3;
}

Output: 0

num3 is not assinged so the value is 0