Comments on Quiz 1 – answers

 

The assumption was that this quiz was related to Lab1a (it said so up top).

In Lab1a,  the if statements could not be reached unless the number entered by the user was in the desired range (1..100).

 

With that in mind,  there was no need to check for negative values or for zero.  That would make d the best answer.

 

a should be rejected because the CPU has to check all three conditions even

though only one of them  is possible.

 

b should be rejected because under the assumptions above, it isn’t possible for there to be an out of range value – but if there could be an out of range value it would be okay.

 

c should be rejected because the CPU has to check all three conditions even though only one of them is possible.

 

d is the best answer because it checks for the most likely case first, and it doesn’t check for something that can’t happen.

 

e should be rejected because it performs a test for a condition that is the default case (start == 1) when under the assumptions above it’s the only possible remaining alternative.

 

If you didn’t know that the values had to be in the range from 1..100, then b would be the best answer.

 

Points allocated:

d – 10

b,e – 9

a,c, - 7