ch(2,3,4) True/False Indicate whether the statement is true or false. ____ 1. Every C++ program must have a function called main. ____ 2. In C++, reserved words are the same as predefined identifiers. ____ 3. A reserved word can be used as a variable name. ____ 4. An identifier can be any sequence of digits, letters, and the underscore character. ____ 5. The following is a legal C++ identifier: Hello! ____ 6. The symbol '*' belongs to the char data type. ____ 7. The number of significant digits in float values is up to 6 or 7. ____ 8. The data type double is a floating-point data type. ____ 9. The maximum number of significant digits in values of the double type is 15. ____ 10. An operator that has only one operand is called a unique operator. ____ 11. The operands of the modulus operator can be decimal numbers, but the modulus operator works better with integers. ____ 12. Multiplication and division have the same operator precedence. ____ 13. The value of the expression 8 * 5 % 3 is 16. ____ 14. If a C++ arithmetic expression has no parentheses, operators are evaluated from left to right. ____ 15. In a mixed expression, all integer operands are converted to floating-point numbers with zero decimal part. ____ 16. A mixed arithmetic expression contains all operands of the same type. ____ 17. In C++, the value of the expression 32/5.0 is 6.4. ____ 18. The explicit conversion of a value from one data type to another is called type casting. ____ 19. The implicit conversion of a value from one data type to another is called type coercion. ____ 20. Suppose x = 6.7. The output of the statement cout << static_cast<int>(x + 0.5) << endl; is 7. ____ 21. Suppose x = 15.7. The output of the statement cout << static_cast<int>(x) / 2 << endl; is 7. ____ 22. Suppose x = 18.9. The output of the statement cout << static_cast<int>(x) % 3 << endl; is 0. ____ 23. The null string contains one character. ____ 24. The value of a variable cannot change during program execution. ____ 25. An input statement can store the value of an arbitrary expression into a variable. ____ 26. Consider the following statements: cin >> x; cin >> y; where x and y are int variables. These statements require the values of x and y to be input on separate lines. ____ 27. Suppose that count is an int variable. The statements ++count; and count++; both increment the value of count by 1. ____ 28. Suppose that count is an int variable. The statements --count; and count--; both decrement the value of count by 2. ____ 29. Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement alpha = beta + 1;. ____ 30. Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement alpha = ++beta;. ____ 31. Suppose x = 8. After the execution of the statement y = x++; y is 9 and x is 8. ____ 32. Suppose a = 4. After the execution of the statement b = ++a; b is 4 and a is 5. ____ 33. Suppose a = 5. After the execution of the statement ++a; the value of a is 6. ____ 34. Suppose x = 10. After the execution of the statement y = x--; y is 10 and x is 8. ____ 35. Suppose a = 5. After the execution of the statement b = --a; b is 3 and a is 3. ____ 36. Suppose a = 15. After the execution of the statement --a; the value of a is 13. ____ 37. \r (Return) moves the insertion point to the beginning of the next line. ____ 38. A C++ program is processed by the preprocessor before being processed by the compiler. ____ 39. All preprocessor statements start with the symbol #. ____ 40. Every C++ program must include the iostream header file. ____ 41. To use the predefined identifiers cin and cout, the program must include the header file iostream and also either include the statement using namespace std; or refer to these identifiers as std:cin and std::cout. ____ 42. The following is a legal C++ program. int main() { return 0; } ____ 43. Executable statements perform calculations, manipulate data, create output, and accept input. ____ 44. When a program is compiled, the listing produced by the compiler shows semantic errors. ____ 45. A comma is also called a statement terminator. ____ 46. In an interactive program, when reading data, prompt lines are used to inform the user what kind of input is required. ____ 47. The pair of characters // is used for single line comments. ____ 48. Multiple line comments are enclosed between /* and */. ____ 49. The following statements are equivalent. x *= y + 2; x = x * y + 2; ____ 50. Suppose that sum is an int variable. The statement sum += 7; is equivalent to the statement sum = sum + 7; ____ 51. Supposing that sum is an int variable. The following statements are equivalent. sum =+ 10; sum = sum + 10; ____ 52. Suppose that product is a double variable. The statement prod *= 0; is equivalent to the statement prod = 0;. ____ 53. It is a good idea to redefine cin and cout in your programs. ____ 54. The extraction operator >> is a binary operator. ____ 55. The left operand of the extraction operator must be an input stream variable. ____ 56. In the statement cin >> x;, x can be a variable or an expression. ____ 57. The statement cout << num; is equivalent to the statement num << cout; ____ 58. If cin and the extraction operator reads two or more numbers from the input stream, the number must be separated by lines. ____ 59. The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. ____ 60. The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. ____ 61. The statement cin >> x >> y; requires the input values for x and y must be separated by at least one whitespace character. ____ 62. 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; ____ 63. 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. ____ 64. During program execution, when entering character data such as letters, you need to enter the single quotes around the character. ____ 65. Entering an int value into a char variable causes serious errors, called input failure. ____ 66. C++ comes with a wealth of functions, called predefined functions, that are written by other programmers. ____ 67. The get function does not skip blanks, but skips the new line character. ____ 68. In the C++ statement, cin.get(u); u must be a variable of type char. ____ 69. The function ignore is used specifically to skip only numbers in a line. ____ 70. The function putback puts the last number extracted from the input stream back into the input stream. ____ 71. The function peek returns the next character in the input stream; it does not remove the character from the input stream. ____ 72. cin is called an input stream object. ____ 73. If input failure occurs in a C++ program, the program terminates immediately and displays an error message. ____ 74. In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device. ____ 75. To use the manipulators setprecison and setw, the program must include the header file iomanip. ____ 76. The manipulator flush clears the buffer only when the buffer is full. ____ 77. You can disable the manipulator left by using the stream function unsetf. ____ 78. Manipulators without parameters are part of the header file iomanip. ____ 79. To use a parameterized manipulator, the program must include the header file iostream. ____ 80. You can use the function readline to read a string containing blanks. ____ 81. Suppose that first and last are variables of type string and the input is Donald Ducky The following statement stores Donald in first and Ducky in last: cin >> first >> ' ' >> last; ____ 82. For file input/output in a program, the program must include the header file iofstream. ____ 83. When the program terminates, the files are closed automatically. ____ 84. A control structure alters the normal sequential flow of control in a program. ____ 85. A program uses repetition to implement a branch. ____ 86. Conditional statements help incorporate decision making into programs. ____ 87. The symbol > is a logical operator. ____ 88. In C++, both ! and != are relational operators. ____ 89. The expression !(x > 10) is equivalent to the expression x < 10. ____ 90. In C++, the logical operator and is &&. ____ 91. In C++, !, &&, and || are called relational operators. ____ 92. The expression !(x < 0) is true only if x is a positive number. ____ 93. The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100. ____ 94. Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true. ____ 95. The value of the expression 'a' < 'A' is true. ____ 96. The value of the expression 7 + 8 <= 15 is true. ____ 97. Suppose P and Q are logical expressions. The expression P || Q is false if either P is false or Q is false. ____ 98. In C++, && has a higher precedence than ||. ____ 99. In C++, all relational operators are evaluated before logical operators. ____ 100. The operators != and == have the same order of precedence. ____ 101. Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is false. ____ 102. Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true. ____ 103. The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4 is true. ____ 104. The expression 'A' < ch < 'Z' is equivalent to the expression 'A' < ch && ch < 'Z' ____ 105. The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable. ____ 106. The output of the C++ code int x = 5; if (x > 10) System.out.println("Hello "); else System.out.println("There. "); System.out.println("How are you?"); is: There. How are you? ____ 107. Including a semicolon before the action statement in a one-way selection causes a syntax error. ____ 108. Consider the following statements. int score; string grade; if (score >= 65) grade = "pass"; else grade = "fail"; If score is equal to 75, the value of grade is "pass". ____ 109. Every if statement must have a corresponding else. ____ 110. If a semicolon is placed after the expression in an if...else statement, the else statement is always executed. ____ 111. The output of the following code is 10. num = 5; if (num >= 5) cout << num <<endl; else cout << num + 5 << endl; ____ 112. A compound statement or block of statements is treated as a single statement. ____ 113. The output of the following C++ code is: Num is greater than 10 num = 20; if (num <= 10) if (num >= 0) cout << "Num is between 0 and 10" << endl; else cout << "Num is greater than 10" << endl; ____ 114. The output of the C++ code: int num = 20; if (num <= 10) if (num >= 0) cout << "Num is between 0 and 10" << endl; else cout << "Num is greater than 10" << endl; is: //Line //Line //Line //Line //Line 1 2 3 4 5 Num is greater than 10. ____ 115. The following blocks of C++ code are equivalent. (Assume that score is an int variable and grade is a char variable.) (i) if (score >= 90) grade = 'A'; if (score >= 80 && score < 90) grade = 'B'; (ii) if (score >= 90) grade = 'A'; else if (score >= 80) grade = 'B'; ____ 116. The expression in the following if statement evaluates to true only if the value of score is 50. if (score = 50) grade = 'Z'; ____ 117. All switch structures include default cases. ____ 118. In C++, case is a reserved word, but break is not a reserved word. ____ 119. In a switch statement, every case must have a break. ____ 120. The output of the following C++ code is 8. alpha = 3; cin >> beta; //Assume input is 5 switch (beta) { case 3: alpha = alpha + 3; case 4: alpha = alpha + 4; break; default: alpha = alpha + 5; } ____ 121. The output of the following C++ code is Legal Age. age = 50; switch (age { case true: cout << break; case false: cout << break; default: cout << } > 21) "Legal Age"; "Below Legal Age"; "Bad Input"; ____ 122. If the expression in an assert statement evaluates to true, the program terminates. Multiple Choice Identify the choice that best completes the statement or answers the question. ____ 123. The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language. a. semantic c. syntax b. logical d. grammatical ____ 124. Which of the following is NOT a special symbol in C++? a. + c. ! b. $ d. ? ____ 125. Which of the following is NOT a reserved word in C++? a. int c. const b. return d. num ____ 126. Which of the following is a legal identifier? a. program! c. 1program b. program_1 d. program 1 ____ 127. Which of the following is a valid C++ identifier? a. 1Stop_and_go c. _Hello_There b. #salaryForTheMonth d. myCounter! ____ 128. Which of the following is a reserved word in C++? a. char c. CHAR b. Char d. character ____ 129. All of the following are examples of integral data types EXCEPT ____. a. int c. double b. char d. short ____ 130. Which of the following is a valid int value? a. 46,259 c. 462.59 b. 46259 d. -32.00 ____ 131. Which of the following is a valid char value? a. -129 c. 128 b. -128 d. 129 ____ 132. What is the floating point notation for 25.611? a. 2.5E1 c. 2.561100E1 b. 2.6 d. 256.1100E1 ____ 133. The memory allocated for a float value is ____. a. 2 bytes c. 8 bytes b. 4 bytes d. 32 bytes ____ 134. Suppose that x, y, z, and w are int variables. The expression x(y+z)/w in C++ is written as a. x * y + z / w c. x * (y + z) / w b. x * y + x * z / w d. x (y + z) / w ____ 135. Suppose that x, y, and z are int variables. The expression x(y+z)in C++ is written as ____. a. x * y + z c. y + x * z b. x * (y + z) d. None of these ____ 136. The value of the expression 33/10 is ____. a. 0.3 c. 3.0 b. 3 d. 3.3 ____ 137. The value of the expression 17 % 7 is ____. a. 1 c. 3 ____ 138. ____ 139. ____ 140. ____ 141. ____ 142. ____ 143. ____ 144. ____ 145. ____ 146. ____ 147. ____ 148. b. 2 d. 4 Operators that have two operands are called ____. a. unary operators c. operators b. binary operators d. expressions The value of the expression 1 + 5 % 3 is ____. a. 0 c. 3 b. 2 d. 4 The value of the expression 26 – 14 % 3 + 1 is ____. a. 0 c. 24 1 b. d. 25 The value of the expression 26 + 14 / 3 + 1 is ____. a. 10 c. 29 b. 14 d. 31 The value of the expression 44/5.0 is ____. a. 0.8 c. 8 b. 8.0 d. 8.8 The value of the expression 36 – 15 % 2.0 + 1 is ____. a. 30 c. 37 31 b. d. This is an illegal C++ expression The value of the expression 46 + 15.0 / 2 - 1 is ____. a. 51.0 c. 52.5 b. 51.5 d. 61.0 The value of the C++ expression 3 + 16 / 7 % 2 is ____. a. 1 c. 19 b. 3 d. 3.0 The value of the C++ expression 14 / 4 + 4.3 is ____. a. 7 c. 7.8 7.3 b. d. 8 The expression static_cast<int>(9.9) evaluates to ____. a. 9 c. 9.9 b. 10 d. 9.0 The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 14.8 c. 13 b. 14 d. 15 ____ 149. Suppose that x is an int variable. Choose the value of x after the following statement executes: x = 15 + static_cast<int>(10.5) / 2; a. x = 20 c. x = 21 b. x = 20.25 d. x = 22 ____ 150. Suppose that alpha is a double variable. Choose the value of alpha after the following statement executes: alpha = 12.5 + static_cast<double>(13) / 2; a. alpha = 18.0 c. alpha = 19.0 b. alpha = 18.5 d. alpha = 19.5 ____ 151. Suppose that alpha is a double variable. Choose the value of alpha after the following statement executes: alpha = 14.0 + static_cast<double>(15 / 2); a. alpha = 21.0 c. alpha = 22.0 b. alpha = 21.5 d. alpha = 22.5 ____ 152. Suppose that x is an int variable. What is the value of x after the following statement executes: x = 15 + static_cast<int>(10.5) / 2; ____ 153. ____ 154. ____ 155. ____ 156. ____ 157. a. 20 c. 21 20.25 b. d. 22 The length of the string "computer science" is ____. a. 14 c. 16 b. 15 d. 18 Which of the following statements about a named constant is NOT true? a. Its content cannot change during program execution. b. Its value can be changed during program execution. c. It is a memory location. d. It is declared using the reserved word const. Suppose that x and y are int variables and x = 10 and y = 20. After the statement: x = x + y; executes, the value of x is ____. a. 10 c. 30 b. 20 d. 30.0 What type of C++ statement(s) stores a value in a variable? a. input b. output c. assignment d. Both a. and c. Given int one; double two; bool four; which of the following assignments are valid? (i) one = 7 * 3 % 4; (ii) 2.3 + 3.5 = two; (iii) four = (2 <= 3); a. Only (i) is valid c. (ii) and (iii) are valid b. (i) and (ii) are valid d. (i) and (iii) are valid ____ 158. Suppose one and two are double variables and the input is 10.5 30.6. After the statement cin >> one >> two; executes, ____. a. one = 10.5, two = 10.5 c. one = 30.6, two = 30.6 b. one = 10.5, two = 30.6 d. one = 11, two = 31 ____ 159. Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____. a. 1 c. 3 b. 2 d. 4 ____ 160. Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. None of these ____ 161. Suppose that alpha and beta are int variables. The statement alpha = beta--; is equivalent to the statement(s) ____. a. alpha = 1 - beta; c. alpha = beta; beta-beta = beta - 1; b. alpha = beta - 1; d. None of these beta--; ____ 162. Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.. a. alpha = 1 + beta; c. alpha = beta; beta = beta + 1; b. alpha = alpha + beta; d. None of the above ____ 163. Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____. a. beta = beta + 1; c. alpha = alpha + beta; alpha = beta; b. alpha = beta + 1; d. None of the above ____ 164. Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a. Sunny \nDay b. Sunny \nDay endl c. Sunny Day d. Sunny \n Day ____ 165. Suppose that x = 5 and y = 6. Choose the output of the following C++ statement: cout << "Sum of " << x << " and " << y << " = " << x + y << endl;. a. Sum of 5 and 6 = 11 c. b. Sum of x and y = 11 d. ____ 166. Which of the following is the new line character? a. \r c. b. \n d. ____ 167. Consider the following code. // Insertion Point 1 Sum of x and y = x + y Sum of 5 and 6 = x + y \l \b using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 ____ 168. ____ 169. ____ 170. ____ 171. ____ 172. ____ 173. In this code, where does the include statement belong? a. Insertion Point 1 c. Insertion Point 3 b. Insertion Point 2 d. None of these ____ are executable statements that inform the user what to do. a. Variables c. Named constants b. Prompt lines d. Expressions Which of the following is the correct syntax for commenting in C++? a. # Enter Comments Here b. <!-- Enter Comments Here --> c. /* Enter Comments Here*/ d. ** Enter Comments Here ** The declaration int a, b, c; is equivalent to which of the following? a. inta , b, c; c. int abc; b. int a,b,c; d. int a b c; Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. a. sum = 0 c. sum = 10 b. sum = 5 d. sum = 15 Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes ____. a. alpha = 5 c. alpha = 50 b. alpha = 10 d. alpha = 50.0 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 c. x = 10, y = 20.7 x = 10, y = 20.0 b. d. x = 10, y = 21.0 ____ 174. 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. ____ 175. 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 = 276 c. ch = ' ', x = 276 b. ch = '2', x = 76 d. ch = 'b', x = 76 ____ 176. 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 = ' ' c. alpha = 17, ch = 'A' alpha = 1, ch = 7 b. d. alpha = 17, ch = 'a' ____ 177. Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z; a. x = 15, y = b. x = 15, y = c. x = 15, y = d. x = 15.0, y ____ 178. Suppose that x and y 76, z = 14 76, z = 0 76.3, z = 14 = 76.3, z = 14.0 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 ____ 179. 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 c. x = 4, ch = ' ', y = 2 b. x = 4, ch = A, y = 12 d. This statement results in input failure ____ 180. Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin >> x >> cin >> y; c. cin << x << y; b. cin >> x >> y; d. cout << x << y; ____ 181. 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' c. 'C' b. 'B' d. '\n' ____ 182. 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 ____ 183. 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' c. 'C' 'B' b. d. '\n' ____ 184. When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear c. delete b. skip d. ignore ____ 185. 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 c. 300 b. 200 d. 320 ____ 186. 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 c. Y b. X d. Z ____ 187. 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 ____ 188. In C++, the dot is an operator called the ____ operator. a. dot access c. data access b. member access d. member ____ 189. 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 c. 25.67 356.88 7623.97 b. 25.67 356.87 7623.97 d. 25.67 356.876 7623.967 ____ 190. 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 c. 55.680 476.860 23.82 b. 55.690 476.860 23.82 d. 55.680 476.859 23.821 ____ 191. Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; a. 1565.683 85.8000 123.98 c. 1565.683 85.7800 123.98 1565.680 85.8000 123.98 b. d. 1565.683 85.780 123.980 ____ 192. Suppose that x = 365, y = 98, and z = 984.576. What is the output of the following statements? cout cout cout cout << << << << fixed << showpoint; setprecision(2); "1234567890123456789" << endl; setw(5) << x << setw(5) << y << setw(7) << z << endl; a. 1234567890123456789 c. 1234567890123456789 365 98 984.58 365 98 984.576 b. 1234567890123456789 d. 234567890123456789 365 98 984.58 365 98 984.576789 ____ 193. What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18 Happy Sleepy b. 12345678901234567890 c. 12345678901234567890 ***18**Happy Sleepy d. 12345678901234567890 ***18**Happy**Sleepy ____ 194. What is the output of the above statements? ***18**Happy Sleepy** cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; a. 123456789012345678901234567890 ####Mickey Donald*****Goofy b. 123456789012345678901234567890 ####Mickey####Donald*****Goofy c. 123456789012345678901234567890 ####Mickey####Donald#####Goofy d. 23456789012345678901234567890 ****Mickey####Donald#####Goofy ____ 195. Suppose that x = 32, y = 62.93, and z = 781.92. What is the output of the following statements? cout cout cout cout << << << << << fixed << showpoint; setprecision(2); "123456789012345678901234567890" << endl; left << setw(5) << "Hi" << right << setw(5) << x setw(7) << y << setw(7) << z << endl; a. 123456789012345678901234567890 Hi 32 62.93 781.92 123456789012345678901234567890 b. Hi32 62.93 781.92 c. 123456789012345678901234567890 Hi 32 62.93 781.92 d. 123456789012345678901234567890 Hi32 62.93 781.92 ____ 196. Suppose that x = 476 and y = 38. What is the output of the following statements? cout << "12345678901234567890" << endl; cout << left << setw(5) << x << setw(5) << y << setw(7) << "Hello" << endl; a. 12345678901234567890 c. 12345678901234567890 476 38 Hello 476 38 Hello b. 12345678901234567890 d. 12345678901234567890 476 38 "Hello" 476 38####Hello ____ 197. Suppose that x = 87 and y = 423. What is the output of the following statements? cout << "12345678901234567890" << endl; cout << setw(5) << x << left << setw(5) << y << setw(7) << "Sunny" << endl; a. 12345678901234567890 87423 Sunny b. 12345678901234567890 87 423 Sunny ____ 198. Consider the following program segment. ifstream infile; int x, y; c. 12345678901234567890 87 423 Sunny d. 12345678901234567890 87 423Sunny //Line 1 //Line 2 ... //Line 3 infile >> x >> y; //Line 4 ____ 199. ____ 200. ____ 201. ____ 202. ____ 203. ____ 204. ____ 205. Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. infile.open("progdata.dat"); b. infile(open,"progdata.dat"); c. open.infile("progdata.dat"); d. open(infile,"progdata.dat"); Suppose that outfile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outfile to the output file? a. outfile("outputData.out"); b. outfile.open("outputData.out"); c. open(outfile,"outputData.out"); d. open.outfile("outputData.out"); In a ____ control structure, the computer executes particular statements depending on some condition(s). a. looping c. selection b. repetition d. sequence What does <= mean? a. less than c. less than or equal to b. greater than d. greater than or equal to Which of the following is a relational operator? a. = c. ! b. == d. && Which of the following is the “not equal to” relational operator? a. ! c. != b. | d. & Which of the following has the highest value? a. '+' c. 'R' b. '*' d. 'a' Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y) a. false c. 0 b. true d. null ____ 206. Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) || ( x <= 0) c. (x > 0) && ( x <= 0) b. (x >= 0) || (x == 0) d. (x > 0) && (x == 0) ____ 207. Which of the following operators has the highest precedence? ____ 208. ____ 209. ____ 210. ____ 211. ____ 212. a. ! c. % b. * d. = Which of the following operators has the lowest precedence? a. ! c. && b. || d. = Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x < 20 c. 10 < x && x < 20 b. (10 < x < 20) d. 10 < x || x < 20 The statement num is less than 0 or num is greater than 50 in C++ is written as ____. a. num < 10 or num > 50 c. num < 10 || num > 50 b. (num < 10) or (num > 50) d. num < 10 && num > 50 The expression in an if statement is sometimes called a(n) ____. a. selection statement c. decision maker b. action statement d. action maker What is the output of the following C++ code? x = 6; if (x > 10) cout << "One "; cout << "Two "; a. One c. One Two b. Two d. Two One ____ 213. What is the output of the following C++ code? x = 0; if (x < 0) cout << "One "; cout << "Two "; cout << "Three"; a. One Two c. Two Three b. Two d. One Two Three ____ 214. What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y – x; cout << x << " " << y << " " << z << endl; a. 35 45 80 c. 35 45 –10 35 45 10 b. d. 35 45 0 ____ 215. What is the output of the following code fragment? x = 10; if (x > 15) x = 0; cout << x << endl; else cout << x + 5; a. 0 c. 10 b. 5 d. None of the above ____ 216. After the execution of the following code, what is the value of sum? sum = 0; num = 10; if (num > 0) sum = sum + 10; else if (num > 5) sum = num + 15; a. 0 c. 20 b. 10 d. 25 ____ 217. When one control statement is located within another, it is said to be ____. a. blocked c. nested b. compound d. closed ____ 218. After the execution of the following code, what will be the value of num if the input value is 5? cin >> num; if (num > 0) num = num + 10; else if (num > 5) num = num + 15; a. 0 c. 15 5 b. d. 25 ____ 219. Suppose x and y are int variables. Consider the following statements. if (x > 5) y = 1; else if (x < 5) { if (x < 3) y = 2; else y = 3; } else y = 4; What is the value of y if x = 6? a. 1 c. 3 b. 2 d. 4 ____ 220. Suppose x and y are int variables. Consider the following statements. if (x > 5) y = 1; else if (x < 5) { if (x < 3) y = 2; else y = 3; } else y = 4; What is the value of y if x = 3? a. 1 c. 3 b. 2 d. 4 ____ 221. Suppose x and y are int variables. Consider the following statements. if (x > 5) y = 1; else if (x < 5) { if (x < 3) y = 2; else y = 3; } else y = 4; What is the value of y if x = 5? a. 1 c. 3 b. 2 d. 4 ____ 222. Suppose x and y are int variables. Consider the following statements. if (x > 5) y = 1; else if (x < 5) { if (x < 3) y = 2; else y = 3; } else y = 4; If the value of y is found to be 2, what is a possible value of x? a. 2 b. 3 ____ 223. What is the output of the following code? c. 5 d. 6 if ( 6 > 8) { cout << " ** " << endl ; cout << "****" << endl; } else if (9 == 4) cout << "***" << endl; else cout << "*" << endl; a. * c. *** b. ** d. **** ____ 224. Suppose x and y are int variables. Consider the following statements.. if (x y if (x y if (x y > 3) = 1; == 3) = 1; < 3) = 2; Which statement is NOT equivalent to this code? a. if (x >= 3) y = 1; else y = 2; b. y = (x >= 3) ? 1 : 2; c. if (x > 3 || x == 3) y = 1; else if (x < 3) y = 2; d. y = (x >= 3) ? 2 : 1; ____ 225. To develop a program, you can use an informal mixture of C++ and ordinary language, called ____. a. assert code c. cppcode b. pseudocode d. source code ____ 226. The appearance of = in place of == resembles a(n) ____. a. syntax error c. compilation error b. silent killer d. input failure ____ 227. Which of the following will cause a semantic error, if you are trying to compare x to 5? a. if (x == 5) c. if (x <= 5) b. if (x = 5) d. if (x >= 5) ____ 228. Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;. a. 2 c. 4 3 b. d. 6 ____ 229. The conditional operator ?: takes ____ arguments. a. 2 c. 4 b. 3 d. 5 ____ 230. Consider the following statement. int y = !(12 < 5 || 3 <= 5 && 3 > x) ? 7 : 9; What is the value of y if x = 2? a. 2 c. 7 b. 3 d. 9 ____ 231. What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4 a. 2 b. 3 ____ 232. What is the output of the following code? c. 4 d. 5 char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section break; case 'B': cout << "section break; case 'C': cout << "section break; case 'D': cout << "section break; default: cout << "section } 1" <<endl; 2" <<endl; 3" <<endl; 4" <<endl; 5" <<endl; a. section 2 b. section 3 ____ 233. What is the output of the following code? char lastInitial = 'A'; c. section 4 d. section 5 switch (lastInitial) { case 'A': cout << "section break; case 'B': cout << "section break; case 'C': cout << "section break; case 'D': cout << "section break; default: cout << "section } 1" <<endl; 2" <<endl; 3" <<endl; 4" <<endl; 5" <<endl; a. section 1 c. section 3 b. section 2 d. section 5 ____ 234. What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } a. 13 c. 17 b. 14 d. 22 ____ 235. What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y – 3; } cout << y << endl; ____ 236. ____ 237. ____ 238. ____ 239. a. 2 c. 8 b. 5 d. None of these A(n) ____ statement causes an immediate exit from the switch structure. a. default c. break b. endl d. exit Which of the following is a valid assert statement? a. assert(); c. assert(a = 2); assert(0); b. d. assert(3 > 2); For a program to use the assert function, it must include which of the following? a. #include <assert> c. #include <assertc> b. #include <cassert> d. #include NDEBUG You can disable assert statements by using which of the following? a. #include <cassert> c. #clear NDEBUG b. #define <assert> d. #define NDEBUG ch(2,3,4) Answer Section TRUE/FALSE 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: T F F F F T T T T F F T F T F F T T T T T T F F F F T F F F F F T F F F F T T F T PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 31 32 32 32 33 37 39 38-39 39 40 40 43 41 | 43 43 45 | 46 45 46 47 47 48 48 48 50 53 58 58 68 68 69 69 69 69 69 69 69 69 76 78 78 79 79 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: T T F F T T T F T F T F T T F F F T F T F T F F T F T F F T T F F T F T F F F F F T T F T F PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 80 81 84-85 85 86 87 87 89 89-90 89 90 117 117 117 117 117-118 118 118 118 118 118 119 122 122 123 125 126 127 128 128 131 131-132 135 136 | 139 141 144 145 145 146 146 | 118 147-148 149 168 168 169 170 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: F F T F F F T F T F T F T T T F F F T F T F F F T F F T F F F F T T F PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 170 175 175 175 176 176 176 177 177 176-177 178 178 178 179 179 181 183-184 183 187 | 188 187 187-188 188 188 187-188 191 192 192 195 202 204 204 205-206 205-209 205-209 212 PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: 31 32 32 32-33 32 32 35 36 MULTIPLE CHOICE 123. 124. 125. 126. 127. 128. 129. 130. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: C B D B C A C B 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: B C B C B B C B C D D D D C B B A C A C A A C B C D D B B C C C A C A B A B C B D C C A B C PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 36 38 39 39-40 39-40 40 40-41 40 43 43 43 45-46 41 | 45 45 45-46 45-46 47-48 47-48 47 | 48 47 | 48 47-48 47-48 50 51 54 54 54 59 68-69 68-69 68-69 68-69 68 | 69 71-74 71 76 82-83 86 87 87 89 90 118 118-120 118-120 118-120 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: C A D B C A B D C A B B C A C A B A C C A A B C C B C D B A A D C C C B C B D B C C A C D A PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 118-120 118-120 118-120 118 118-120 126 126 126 127 128-129 128-129 131 135-136 135-136 135-136 135-136 | 138 142-143 142-143 135-138 | 144 144 | 138 144 | 138 148 148 168 170 170 170 172 176 176-177 178 178 183-184 183-184 185 185-186 185-186 187-189 189 192 192 192 192 192 192 192 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: A D B B B A B D C D A C A C D B D PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 192 195 196 203 202 203 203 203 203 204-206 204-206 204-206 204-206 204-205 212 212 213
© Copyright 2025 Paperzz