Chapter 3 Quiz

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

11. In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ; a. 6 - 3 b. 3 * 2 c. 2 + 7 d. 7 - 10 e. 10 / 2

b. 3 * 2

29. What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; a. 2.0 b. 4.0 c. 1.5 d. 6.0

b. 4.0

The cin << statement will stop reading input when it encounters a newline character.

TRUE

The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.

TRUE

When C++ is working with an operator, it strives to convert the operands to the same type.

TRUE

When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.

TRUE

28. What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2; a. 13 b. 18 c. 0 d. unknown

a. 13

33. Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } a. 6 b. 8 c. 9 d. 7

a. 6

22. Which is true about the following statement? cout << setw(4) << num4 << " "; a. It allows four spaces for the value in the variable num4. b. It outputs "setw(4)" before the value in the variable num4. c. It should use setw(10) to output the value in the variable num10. d. It inputs up to four characters stored in the variable num4. e. None of these

a. It allows four spaces for the value in the variable num4.

26. The statement cin >> setw(10) >> str; will read up to this many characters into str. a. Nine b. Ten c. Eleven d. Eight e. None of these

a. Nine

21. When converting some algebraic expressions to C++, you may need to insert ___________ that do not appear in the algebraic expression. a. Parentheses b. Exponents c. Calculations d. Coercions e. None of the above

a. Parentheses

7. This function tells the cin object to skip one or more characters in the keyboard buffer. a. cin.ignore b. cin.jump c. cin.hop d. cin.skip; e. None of the above

a. cin.ignore

30. Which statement is equivalent to the following? number += 1; a. number = number + 1; b. number + 1; c. number = 1; d. None of these

a. number = number + 1;

10. You can use these to override the rules of operator precedence in a mathematical expression. a. [Brackets] b. (Parentheses) c. {Braces} d. The escape character \ e. None of these

b. (Parentheses)

6. What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4); a. .3 b. 0 c. .275229 d. 3.3 e. None of these

b. 0

32. What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3; a. 3 b. 30 c. 15 d. 2

c. 15

2. The ______ operator always follows the cin object, and the ______ operator follows the cout object. a. binary, unary b. conditional, binary c. >>, << d. <<, >> e. None of the above

c. >>, <<

20. Associativity is either right to left or a. Top to bottom b. Front to back c. Left to right d. Undeterminable e. None of the above

c. Left to right

12. When the final value of an expression is assigned to a variable, it will be converted to: a. The smallest C++ data type b. The largest C++ data type c. The data type of the variable d. The data type of the expression e. None of the above

c. The data type of the variable

16. This statement will pause the screen, until the [Enter] key is pressed. a. cin; b. cin.getline(); c. cin.get(); d. cin.ignore(); e. cin.input();

c. cin.get();

Arithmetic operators that share the same precedence have right to left associativity.

FALSE

If you want to know the length of the string that is stored in a string object, you can call the object's size member function.

FALSE

In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.

FALSE

The fixed manipulator causes a number to be displayed in scientific notation.

FALSE

The statement will output $5.00 to the screen. cout << setprecision(5) << dollars << endl;

FALSE

When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.

FALSE

5. When this operator is used with string operands it concatenates them, or joins them together. a. & b. * c. % d. + e. None of the above

d. +

18. Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5; a. 0 b. 1 c. 2 d. -3 e. None of these

d. -3

27. What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ; a. 8 b. 6 c. 1.5 d. 2

d. 2

34. Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << MY_VAL << endl; 9 return 0; 10 } a. 6 b. 8 c. 9 d. 7

d. 7

23. The total number of digits that appear before and after the decimal point is sometimes referred to as: a. floating points b. significant digits c. precision d. b and c e. None of these

d. b and c

17. To use the rand() function, you must #include this header file in your program. a. iostream b. iomanip c. iorand d. cstdlib e. None of these

d. cstdlib

9. You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written? a. cin << length, width, height; b. cin.get(length, width, height); c. cin >> length >> width >> height; d. cin >> length, width, height; e. cin << length; width; height;

b. cin.get(length, width, height);

25. When using the sqrt function you must include this header file. a. cstdlib b. cmath c. cstring d. iostream e. iomanip

b. cmath

8. The function, pow(x, 5.0), requires this header file. a. cstdlib b. cmath c. cstring d. iostream e. iomanip

b. cmath

4. ___________reads a line of input, including leading and embedded spaces, and stores it in a string object. a. cin.get b. getline c. cin.getline d. get e. None of these

b. getline

3. In any program that uses the cin object, you must include the ___________. a. compiler b. iostream header file c. linker d. >> and << operators e. None of the above

b. iostream header file

13. When a variable is assigned a number that is too large for its data type, it: a. underflows b. overflows c. reverses polarity d. exceeds expectations e. None of the above

b. overflows

1. The _________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. a. Output stream b. cin object c. cout object d. Preprocessor e. None of the above

b. cin object

31. Which statement is equivalent to the following? x = x * 2; a. x * 2; b. x *= 2; c. x = x * x; d. None of these

b. x *= 2;

24. This stream manipulator forces cout to print the digits in fixed-point notation. a. setprecision(2) b. setw(2) c. fixed d. setfixed(2) e. None of these

c. fixed

19. Which statement will read an entire line of input into the following string object? string address; a. cin << address; b. cin address; c. getline(cin, address); d. cin.get(address); e. None of the above

c. getline(cin, address);

15. This manipulator causes the field to be left-justified with padding spaces printed to the right. a. left_justify b. right c. left d. left_pad e. None of these

c. left

14. This manipulator is used to establish a field width for the value immediately following it. a. field_width b. set_field c. setw d. iomanip e. None of the above

c. setw


Ensembles d'études connexes

Managerial Leadership | Chapter 3 Test Bank

View Set

History Guided Reading Activity 3-3

View Set

Chapter 11; Special Senses: The Eyes and Ears

View Set

Common Phrases for Ordering at a Restaurant/Cafe

View Set

NRS 240 TBL 2: postpartum complications

View Set

Midterm Multiple Choice (Chapter 65, 66, 67, 68)

View Set