< previous page page_126 next page >

Page 126
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. result = 45 / 8 * 4 + 2;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
e. result = 17 + (21 % 6) * 2;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
f. result = int(4.5 + 2.6 * 0.5);
3. Translate the following C++ code into algebraic notation. (All variables are float variables.)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
y = -b + sqrt(b * b - 4.0 * a * c);
4. Given the following program fragment:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int   i;
int   j;
float z;

i = 4;
j = 17;
z = 2.6;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
determine the value of each expression below. If the result is a floating point value, include a decimal point in your answer.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. i / float(j)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. 1.0 / i + 2
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. z * j
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. i + j % i
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
e. (1 / 2) * i
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
f. 2 * i + j - i
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
g. j / 2
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
h. 2 * 3 - 1 % 3
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
i. i % j  / i
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
j. int(z + 0.5)
5. To use each of the following statements, a C++ program must #include which header file(s)?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. cout < x;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. int1 = abs(int2);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. y = sqrt(7.6 + x);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. cout < y < endl;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
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 >