Last MC
- Overview
- Q14 Error in isIncreasing procedure
- A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements.
- Which of the following changes is needed for the program to work as intended?
- Q66 Set bonus points based on timer
- In a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows.
- If timer is less than 30, then 500 bonus points are awarded.
- If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded.
- If timer is greater than 60, then 1500 bonus points are awarded.
- Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ?
- Select two answers.
- Q14 Error in isIncreasing procedure
Overview
Overall, I would say that I did pretty good. I definitely need more practice since it took me a relatively long time to answer each question. However, the main problem was the density of the questions. In other words, as I reached the final 5-10 questions of the test, my attention span became non-existent. So I need to get used to answering 50 questions in a relatively short amount of time.
Q14 Error in isIncreasing procedure
A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements.
Which of the following changes is needed for the program to work as intended?
A: In line 3, 2 should be changed to 1.
B: In line 6, < should be changed to ≥.
C: Lines 8 and 12 should be interchanged.
D: Lines 10 and 11 should be interchanged.
RESPONSE: In line 6, < should be changed to ≥.
CORRECT ONE: Lines 8 and 12 should be interchanged.
EXPLANATION: Correct. As is, the procedure traverses numberList from left to right and returns true whenever it encounters a value that is less than the preceding value. If it never encounters such a value, false is returned. This has the effect of returning true whenever the list is not increasing and returning false whenever the list is increasing, which is the opposite of what is intended. By interchanging lines 8 and 12, the procedure will return true or false appropriately.
Q66 Set bonus points based on timer
In a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows.
If timer is less than 30, then 500 bonus points are awarded.
If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded.
If timer is greater than 60, then 1500 bonus points are awarded.
Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ?
Select two answers.
RESPONSE: C D
CORRECT ONE: A D
EXPLANATION: Correct. In this code segment, if timer is greater than 60, bonus is assigned 1500 in the first IF block. If timer is between 30 and 60, inclusive, bonus is assigned 1000 in the second IF block. If timer is less than 30, bonus is assigned 500 in the third IF block. The correct number of bonus points is assigned to bonus for all possible values of timer. This code segment assigns 500 bonus points by default. If timer is less than 30, no additional bonus points are added. If timer is between 30 and 60 inclusive, bonus is incremented by 500 in the first IF block. If timer is greater than 60, bonus is incremented by 500 twice (once in each IF block). The correct number of bonus points is assigned to bonus for all possible values of timer.