Quiz 2 Date Name MULTIPLE CHOICE Choose the one alternative

Quiz 2 Date Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the q 1) The do-while loop is a to iterate at least once. loop that is ideal in situations where you always want the l A) pre-test B) null-terminated C) post-test D) infinite E) None of these 2) A file must be before data can be written to or read from it. A) closed B) buffered C) initialized D) opened E) None of these 3) In a for statement, this expression is executed only once A) validation B) initialization C) null D) test E) None of these 4) What will the following code display? int number 6 int x 0; x number; cout

Solution

1. C) Post test. Because test condition of do-while loop is situated after the body of the loop.

2. D) A file must be open before any read or right.

3. B) Initialization.

4. A) 5 Because x is assigned by variable \'number\' which came with a prefix decrement operator.

5. D) Prefix increment. Incase of prefix increment, increment operator use before the variable. And it increases the value of the variable before any operation on the variable.

6. C) because the line which prints \"You failed the test\" doesn\'t comes under any if condition. So it would be printed as usual. second if condition is true so it will print \"you passed the test\".

7. C) 20 Because it will loop for 20, 19, 18...2,1 both 20 and 1 is included.

8. C) It will print 1. Because when we use conditional operator x,y,z is being treated as boolean value. As none of those contains null so anything except null is treated as true.

9. A) because x starts with value 0 and increases till less than 5 which is 4. And the \'endl\' at the end of the print statement causes line break

10. C) Because the condition (donuts !=10) is false because the value of donuts is 10 indeed. So else part is executed which adds 2 to the value of donuts

11. C) Because the condition (score > 95) is false as the value of the score is 40. So anything under if condition will not execute. As there is no curly braces after \'if\' statement so only one instruction (The instruction just after the if condition) will comes under if statement. So that line won\'t execute. Last two print instruction will execute.

12. B) Logical operator. Because logical operator takes boolean value from two expression and performs logical operations.

13. D) For loop

14. A) !

15. C) it closes the file

16. D) All of these. Because all of A, B and C can cause undesirable output

 Quiz 2 Date Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the q 1) The do-while loop is a to iterate at least o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site