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

1. Determine the value of the following expressions. a. toupper(\'b\') b. tolowe

ID: 3629294 • Letter: 1

Question

1. Determine the value of the following expressions.

a. toupper('b')

b. tolower('C');

c. pow(3.0,3.0);

d. sqrt(81.0);

e. fabs(-1.23);

f. floor(22.46);

g. ceil(33.3);

2. Using the functions in the cmath library, write the following mathematical formulas as C++ expressions.

a. 3.02.4

b. (x - y)1/2 Note: the ½ power is the square root

c. |y - 42.3|

d.( -b + (b2 - 4ac)1/2) / 2a

3. Consider the following functions:

int func1(int x)
{
int r, s;

r = 2 * x;

if (r > 10)
{
s = x / 2;
}
else
{
s = x / 3;
}
return s - 2;
}

int func2(int a, int b)
{
int r, s;

s = 0;
for(r = a; r < b; r++)
{
s++;
}
return s;
}

What is the output from the following program fragments?

int a, b;

a. a = 10;
cout << func1(a) << endl;
b. a = 5; b = 12;
cout << func2(a, b) << endl;
c. a = 8;
b = func1(a);
cout << a << " " << b << " " << func2(a, b) << endl;

Explanation / Answer

1. Determine the value of the following expressions.

a. toupper('b')     B

b. tolower('C');    c

c. pow(3.0,3.0);   27

d. sqrt(81.0);      9

e. fabs(-1.23);      1.23

f. floor(22.46);     22

g. ceil(33.3);        34

2. Using the functions in the cmath library, write the following mathematical formulas as C++ expressions.

a. 3.02.4       ?

b. (x - y)1/2 Note: the ½ power is the square root     sqrt(x-y);

c. |y - 42.3|                                            fabs(y-4.23);     

d.( -b + (b2 - 4ac)1/2) / 2a         (-b+sqrt(b*b-4*a*c))/2*a;

3. Consider the following functions:

int func1(int x)
{
int r, s;

r = 2 * x;

if (r > 10)
{
s = x / 2;
}
else
{
s = x / 3;
}
return s - 2;
}

int func2(int a, int b)
{
int r, s;

s = 0;
for(r = a; r < b; r++)
{
s++;
}
return s;
}

What is the output from the following program fragments?

int a, b;

a. a = 10;
cout << func1(a) << endl;      3
b. a = 5; b = 12;
cout << func2(a, b) << endl;     7
c. a = 8;
b = func1(a);
cout << a << " " << b << " " << func2(a, b) << endl;    8 2 0