<p> COSC 1320 C++ PROGRAMMING Homework 3</p><p>Part I True/False</p><p>1. To decrement a number means to increase its value by one.</p><p> a. True b. False</p><p>2. The increment and decrement operators can be used in mathematical expressions and in cout statements; however, they cannot be used in relational expressions.</p><p> a. True b. False</p><p>3. The block of code that follows a while condition can contain an unlimited number of statements, provided they are enclosed in braces.</p><p> a. True b. False</p><p>4. A while loop requires a semicolon after the test expression and before the body of the loop.</p><p> a. True b. False</p><p>5. A while loop is somewhat limited, because the counter can only count up, not down.</p><p> a. True b. False</p><p>6. A while loop requires a semicolon after the test expression and before the body of the loop.</p><p> a. True b. False</p><p>7. A while loop is somewhat limited, because the counter can only count up, not down.</p><p> a. True b. False</p><p>8. An initialization expression may be omitted from the for loop if no initialization is required.</p><p> a. True b. False</p><p>9. When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop. </p><p> a. True b. False 10. A while loop is somewhat limited because the counter can only be increased by one each time through the loop. </p><p> a. True b. False</p><p>11. When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop. </p><p> a. True b. False</p><p>12. If you want to stop a loop before it goes through all its iterations, the break statement may be used.</p><p> a. True b. False</p><p>13. The increment and decrement operators can be used in relational expressions as well as in mathematical expressions and in cout statements.</p><p> a. True b. False</p><p>14. The continue statement lets you leave a loop and continue with the statement following it.</p><p> a. True b. False</p><p>15. A do-while loop requires a semicolon at the end of the loop after the test expression.</p><p> a. True b. False</p><p>Part II Multiple Choice</p><p>16. _____ and _____ are operators that add and subtract one from their operands.</p><p> a. plus and minus b. ++ and -- c. binary and unary d. conditional and relational e. None of these</p><p>17. The ++ operator </p><p> a. is a unary operator b. adds one to the value of its operand c. can operate in prefix or postfix mode d. All of the above e. b and c, but not a 18. What will the following code print?</p><p> num = 8; cout << --num << " "; cout << num++;</p><p> a. 7 7 b. 7 8 c. 8 8 d. 8 7 e. None of these </p><p>19. What will the following code print?</p><p> num = 5; cout << num++ << " "; cout << num--;</p><p> a. 5 5 b. 5 6 c. 6 6 d. 6 5 e. None of these</p><p>20. The while loop has two important parts: an expression that is tested for a true or false value, and a:</p><p> a. statement or block that is repeated as long as the expression is true b. statement or block that is repeated only if the expression is false c. single line of code that is repeated once, if the expression is true d. statement or block that is repeated once, if the expression is true e. None of these</p><p>21. The while loop is a(n) ______loop.</p><p> a. pretest b. posttest c. infinite d. limited e. None of these</p><p>22. The statements in the body of a while loop might never be executed, whereas the statements in the body of a do-while loop are always executed:</p><p> a. at least once b. at least twice c. exactly once d. forever until the user hits the break key e. None of these</p><p>23. A sentinel is a special value that</p><p> a. is used for data validation b. must be Boolean c. marks the end of a list of values d. must be a negative number e. None of the above 24. For data validation, it is best to use</p><p> a. an if statement b. a while loop c. a for loop d. a nested loop e. a switch statement</p><p>25. The statements in the body of a do-while loop will always be executed</p><p> a. at least once b. at least twice c. regardless of the value of the test expression d. forever until the user hits the break key e. None of these</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages4 Page
-
File Size-