< previous page
page_126
next page >
Page 126
d.
result = 45 / 8 * 4 + 2;
e.
result = 17 + (21 % 6) * 2;
f.
result = int(4.5 + 2.6 * 0.5);
3. Translate the following C++ code into algebraic notation. (All variables are
float
variables.)
y = -b + sqrt(b * b - 4.0 * a * c);
4. Given the following program fragment:
int i;
int j;
float z;
i = 4;
j = 17;
z = 2.6;
determine the value of each expression below. If the result is a floating point value, include a decimal point in your answer.
a.
i / float(j)
b.
1.0 / i + 2
c.
z * j
d.
i + j % i
e.
(1 / 2) * i
f.
2 * i + j - i
g.
j / 2
h.
2 * 3 - 1 % 3
i.
i % j / i
j.
int(z + 0.5)
5. To use each of the following statements, a C++ program must #
include
which header file(s)?
a.
cout < x;
b.
int1 = abs(int2);
c.
y = sqrt(7.6 + x);
d.
cout < y < endl;
e.
cout < setw(5) < someInt;
6. Evaluate the following expressions. If the result is a floating point number, include a decimal point in your answer.
< previous page
page_126
next page >