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

CAN YOU PLEASE ANSWER THIS IN C++ What is the output of the given program segmen

ID: 3726528 • Letter: C

Question

CAN YOU PLEASE ANSWER THIS IN C++

What is the output of the given program segment? Assume that the <cmath> file has been included.

double x = -5.49;

cout<<ceil(x)<<endl<<fabs( x) <<endl <<floor( x );

What is output by the following segment when function f1 is invoked?

void f1()

{

int x = 5;

f2( x );

            cout << x << endl;

}

void f2( int x )

{

            x += 5;

            cout << x << endl;

}

What is the output of

cout<< mystery ( 6, 2, 5) << endl;

assuming the following definition of mystery?

int mystery( int x, int y, int z)

{

            int value = x;

if (y > value )

                        value = y;

if (z > value )

                        value = z;

return value;

}

Explanation / Answer

a)

Ceil():the value is rounded down to smallest integer that is greater than or equal to x so -5.49 will -5

Fabs():converts the given number into the absolute value so value returns for -5.49 is 5.49

Floor(): the values is rounded down to the nearest integer so 5.49 will be 6

Output will be:

-5

5.49

-6

b) when the function f1 is invoked creates the memory for local variable and stores the value 5. Then calls the function f2.

In function f2 the x stored in the function f2 is increment and prints the value. (it will not reflect to x stored in f1 function).

After the control returns from f2 to f1 he x value will be printed as 5

output will be:

10

5

c)mystery function stores x in value (ie.,6) and then after checking the conditions the biggest number is stored in value. But in this case two if statement fails and the value returned will be 6

output will be:

6

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