True/False
1. In a C++ expression, all additions are performed before any subtractions.
2. In C++, the value of the expression
3. Execution of the statement
someInt = 3 * int(someFloat);
does not change the contents of the variable
someFloat in memory.4. In a C++ expression without parentheses, all operations are performed in order from left to right.
5. If
someFloat is a variable of type float, the statementsomeFloat = 395;
causes
someFloat to contain an integer rather than floating point value.6. In C++, the expression
(a+b/c)/2 is implicitly parenthesized as ((a+b)/c)/2.8. Assuming
sqrt(fabs(3.8 * x + 9.4 * y))
is a valid use of the
sqrt and fabs library functions.9. The value of the expression
a+b*c+d is different from the value of the expression a+b*c+d.10. When a floating point value is assigned to an integer variable, the fractional part is truncated.
11. A value-returning function is always called (invoked) by using its name and parameter list as a complete, stand-alone statement.
12. A void function is always called (invoked) by using its name and parameter list as a complete, stand-alone statement.
13. To use a C++ library function, you must use an
#include directive to include the appropriate header file.14. If the
int variable someInt contains the value 26, the statementcout << "someInt";
outputs the value 26.
15. The
setprecision manipulator is used to increase or decrease the precision of floating point numbers that are stored in the computer's memory unit.16. The
endl manipulator is used to control horizontal spacing within an output line.17. The
setw manipulator is used only for formatting numeric values and strings, not char data.
Multiple Choice
18. Among the C++ operators
a.
+ and -b.
* and /c.
*, /, and %d.
+, -, and %e.
+, -, and *19. The value of the C++ expression
a. 0.0
b. 0
c. 3.75
d. 3
e. 0.15
20. Assuming all variables are type
d+e
a.
a + b * c / d + eb.
(a + b) * c / d + ec.
(a + b) * c / (d + e)d.
(a + b * c) / d + ee.
(a + b) c / (d + e)21. Given that
x = num + 2;
a. 7
b. 7.0
c. 5
d. 5.0
e. nothing—a compile-time error occurs
22. Given that
num = x + 2;
a. 86.7
b. 86
c. 87
d. 87.0
e. nothing—a compile-time error occurs
23. The value of the C++ expression
a. 13
b. 1
c. 8
d. 16
e. none of the above
24. Given that
x = num / 4 + 3.0;
a. 12.5
b. 13
c. 12
d. 12.0
e. nothing—a compile-time error occurs
25. One of the following statements does not show a proper use of the
a.
y = sqrt(x);b.
y = 3.85 * sqrt(x + 4.2);c.
cout << sqrt(x);d.
sqrt(25.0 * x);e.
y = sqrt(sqrt(x)) - x;26. If the
a. 0.8
b. 0
c. 0.0
d. 1.0
e. 1
27. If
a.
cout << int(x);b.
cout << int(x) + 0.5;c.
cout << int(x + 0.5);d.
cout << float(x + 0.5);e.
cout << x + int(0.5);28. Which expression does not correctly compute the mathematical average of the
a.
float(int1 + int2 + int3) / 3.0
b.
(int1 + int2 + int3) / 3.0c.
float((int1 + int2 + int3) / 3)d.
float(int1 + int2 + int3) / 3e. b and d above
29. If
a.
DoSomething(n);b.
DoSomething(3*n + 24);c.
length = DoSomething(width);d. b and c above
e. a, b, and c above
30. What is the output of the following program fragment?
cout << "Barrel" << endl;
cout << ' ';
cout << "of";
cout << "Laughs" << endl;
a.
Barrel ofLaughs
b.
Barrelof Laughs
c.
Barrelof
Laughs
d.
Barrelof Laughs
e.
BarrelofLaughs
31. What is the output of the following program fragment?
age = 29;
cout << "Are you" << age << "years old?" << endl;
a.
Are you29years old?b.
Are you 29 years old?c.
Are you29 years old?d.
Are you 29years old?e.
Are you age years old?32. What is the output of the following program fragment? (
alpha = 2463;
beta = 72;
cout << "123456789" << endl
<< setw(5) << alpha << endl
<< setw(5) << beta << endl;
a.
12345678924630
72000
b.
1234567892463
72
c.
1234567892463
72
d.
123456789
2463
72
e. none of the above
33. What is the output of the following program fragment? (
x = 25.6284;
cout << "**" << setw(6) << setprecision(1) << x << endl;
a.
**25.6284b.
** 25.628400c.
**25.628d.
** 25.6e.
**25.634. If
1234567890
Score: 78
a.
cout << "1234567890" << endl<< "Score: " << testScore << endl;
b.
cout << "1234567890" << endl<< "Score:" << " " << testScore << endl;
c.
cout << "1234567890" << endl<< "Score:" << setw(4) << testScore << endl;
d. a and b above
e. a, b, and c above
35. Formatting a program in a consistent, readable style is valuable to
a. the person who writes the program.
b. other people who need to understand and work with the program.
c. the C++ compiler.
d. a and b above
e. a, b, and c above
Fill-In
36. ____________________ are the rules by which C++ operators are ordered.
37. Give a C++ arithmetic expression that computes the average of the
38. Give a C++ arithmetic expression that multiplies the
float variable currentSales by three percent, then adds a constant named BASE_PAY: ____________________39. The expression
int(someFloat) is an example of a(n) ____________________ operation.40. When an expression contains several operators with the same precedence, the operands are combined according to the ____________________ of the operators.
41. The implicit (automatic) conversion of a value from one data type to another is called ____________________.
42. A(n) ____________________ expression is an arithmetic expression that contains operands of different data types.
43. The explicit conversion of a value from one data type to another is called ____________________.
44. A prewritten function that is supplied by the C++ system and available for any programmer to use is called a(n) ____________________.
45. In the statement
y = SomeFunc(3);
the number 3 is known as the function's ____________________.
46. The mechanism that transfers control to a function is called a(n) ____________________.
47. A(n) ____________________ is a mechanism by which functions communicate with each other.
48. A(n) ____________________ is a function that returns a single value to its caller and is invoked from within an expression.
49. The C++ ____________________ is a collection of prewritten functions and declarations that are available for use by any C++ programmer.
50. A(n) ____________________ is a function that does not return a function value to
its caller and is invoked as a complete, stand-alone statement.
51. If
int1 and int2 are int variables and the following statements are executed:int1 = 45;
int2 = 89;
cout << setw(4) << int1 << setw(5) << int2 << endl;
show the resulting output, using a pound sign (#) to indicate each blank: ____________________
52. If
int1 and int2 are int variables and the following statements are executed:int1 = 45;
int2 = 89;
cout << setw(4) << int1 << int2 << endl;
show the resulting output, using a pound sign (#) to indicate each blank: ____________________