BTE320 Chapter 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

3. The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y; a. True b. False

ANSWER: False

5. The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. a. True b. False

ANSWER: False

8. If input failure occurs in a C++ program, the program terminates immediately and displays an error message. a. True b. False

ANSWER: False

9. In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device. a. True b. False

ANSWER: False

4. The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. a. True b. False

ANSWER: True

6. When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character. a. True b. False

ANSWER: True

7. Entering a char value into an int variable causes serious errors, called input failure. a. True b. False

ANSWER: True

13. Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; a. x = 15, ch = 'A', y = 73.2 b. x = 15, ch = 'A', y = 73.0 c. x = 15, ch = 'a', y = 73.0 d. This statement results in an error because there is no space between 15 and A.

ANSWER: a

17. Suppose that x and y are int variables, z is a double variable, and the input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z; a. x = 28, y = 32, z = 0.6 b. x = 28, y = 32, z = 12.0 c. x = 28, y = 12, z = 32.6 d. x = 28, y = 12, z = 0.6

ANSWER: a

18. Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; a. ch = '2', x = 76 b. ch = '276', x = '.' c. ch = ' ', x = 276 d. ch = 'b', x = 76

ANSWER: a

20. Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha; a. ch1 = 'A', ch2 = ' ', alpha = 18 b. ch1 = 'A', ch2 = '1', alpha = 8 c. ch1 = 'A', ch2 = ' ', alpha = 1 d. ch1 = 'A', ch2 = '\n', alpha = 1

ANSWER: a

24. Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2; a. W b. X c. Y d. Z

ANSWER: a

28. Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl; a. 55.680 476.859 23.82 b. 55.690 476.860 23.82 c. 55.680 476.860 23.82 d. 55.680 476.859 23.821

ANSWER: a

33. Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip c. ifstream d. pmanip

ANSWER: a

12. Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin >> x >> cin >> y; b. cin >> x >> y; c. cin << x << y; d. cout << x << y;

ANSWER: b

21. Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3); a. 'A' b. 'B' c. 'C' d. '\n'

ANSWER: b

25. Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2; a. W b. X c. Y d. Z

ANSWER: b

26. In C++, the dot is an operator called the ____ operator. a. dot access b. member access c. data access d. member

ANSWER: b

1. It is a good idea to redefine cin and cout in your programs. a. True b. False

ANSWER: False

2. In the statement cin >> x;, x can be a variable or an expression. a. True b. False

ANSWER: False

11. Suppose that x is an int variable and y is a double variable and the input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;. a. x = 10, y = 20 b. x = 10, y = 20.0 c. x = 10, y = 20.7 d. x = 10, y = 21.0

ANSWER: c

14. Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch; a. alpha = 17, ch = ' ' b. alpha = 1, ch = 7 c. alpha = 17, ch = 'A' d. alpha = 17, ch = 'a'

ANSWER: c

16. Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; a. 'A' b. 'B' c. 'C' d. '\n'

ANSWER: c

23. Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; a. 100 b. 200 c. 300 d. 320

ANSWER: c

27. Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl; a. 25.67 356.87 7623.96 b. 25.67 356.87 7623.97 c. 25.67 356.88 7623.97 d. 25.67 356.876 7623.967

ANSWER: c

19. Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y; a. x = 4, ch = 2, y = 12 b. x = 4, ch = A, y = 12 c. x = 4, ch = ' ', y = 2 d. This statement results in input failure

ANSWER: d

22. When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear b. skip c. delete d. ignore

ANSWER: d

39. In C++, the dot is an operator called the ____________________operator.

ANSWER: member access

37. The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream.

ANSWER: peek


Conjuntos de estudio relacionados

Texas 30-Hour Promulgated Contract Forms

View Set

Histology Final Exam (Lecture - Quizzes 1 -9)

View Set

BMS130 (Physio) - Respiration (Week 6)

View Set

World History Unit 2 - Exploration and Conquest

View Set

Trimester 1 and 2 history exam questions

View Set