True/False

1. In a C++ expression, all additions are performed before any subtractions.

2. In C++, the value of the expression 3 + 2 * 6 is 15.

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 statement

someFloat = 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.

  1. Integer values and floating point values are stored differently inside the computer.

8. Assuming x and y are variables of type float, the expression

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 statement

cout << "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 +, -, *, /, and %, which ones have the lowest precedence?

a. + and -

b. * and /

c. *, /, and %

d. +, -, and %

e. +, -, and *

19. The value of the C++ expression 3 / 4 * 5 is:

a. 0.0

b. 0

c. 3.75

d. 3

e. 0.15

20. Assuming all variables are type float, the C++ expression for (a+b)c is:

d+e

a. a + b * c / d + e

b. (a + b) * c / d + e

c. (a + b) * c / (d + e)

d. (a + b * c) / d + e

e. (a + b) c / (d + e)

21. Given that x is a float variable and num is an int variable containing the value 5, what will x contain after execution of the statement

x = num + 2;

a. 7

b. 7.0

c. 5

d. 5.0

e. nothing—a compile-time error occurs

22. Given that x is a float variable containing the value 84.7 and num is an int variable, what will num contain after execution of the statement

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 11 + 22 % 4 is:

a. 13

b. 1

c. 8

d. 16

e. none of the above

24. Given that x is a float variable and num is an int variable containing the value 38, what will x contain after execution of the statement

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 sqrt library function. Which one is the wrong statement? (Assume all variables are float variables.)

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 int variables int1 and int2 contain the values 4 and 5, respectively, then the value of the expression float(int1 / int2) is:

a. 0.8

b. 0

c. 0.0

d. 1.0

e. 1

27. If x is a float variable containing a positive value, which of the following statements outputs the value of x, rounded to the nearest integer?

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 int variables int1, int2, and int3?

a. float(int1 + int2 + int3) / 3.0

b. (int1 + int2 + int3) / 3.0

c. float((int1 + int2 + int3) / 3)

d. float(int1 + int2 + int3) / 3

e. b and d above

29. If DoSomething is a void function that takes an int expression as a parameter, which of the following is an incorrect statement? (Assume all variables are int variables.)

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 of

Laughs

b. Barrel

of Laughs

c. Barrel

of

Laughs

d. Barrel

of Laughs

e. Barrel

ofLaughs

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 and beta are int variables.)

alpha = 2463;

beta = 72;

cout << "123456789" << endl

<< setw(5) << alpha << endl

<< setw(5) << beta << endl;

a. 123456789

24630

72000

b. 123456789

2463

72

c. 123456789

2463

72

d. 123456789

2463

72

e. none of the above

33. What is the output of the following program fragment? (x is a float variable.)

x = 25.6284;

cout << "**" << setw(6) << setprecision(1) << x << endl;

a. **25.6284

b. ** 25.628400

c. **25.628

d. ** 25.6

e. **25.6

34. If testScore is an int variable containing the value 78, which output statement will produce the output

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 float variables score1, score2, and score3: ____________________

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: ____________________