Question 1 Report
Fig. 1 shows part of the control program for a warehouse robot. At the end of a patrol, the robot selects a new aisle to inspect. The warehouse has aisles numbered 1 to 9. The random aisle number is passed to a subroutine that moves the robot. If an aisle is closed, the program must select another number. A pointer on the warehouse board shows the robot's current position, but it does not affect the random command.
(a) Explain what the program does when the first random aisle is closed. [1]
(b) When aisle 6 is closed for a whole day, explain why the robot could still generate the number 6 several times. [2]
A museum is developing a touchscreen quiz about local engineering. After a visitor answers a question, the program selects a new question number so that repeat visitors receive varied questions. There are 25 questions stored in an array numbered 0 to 24. The programmer writes a command that produces random integers from 1 to 25, then uses the result as an array pointer. During testing, an error message sometimes appears and question 0 is never displayed. The main program must continue to work when a visitor starts a new quiz.
(a) Explain why a random result of 25 can cause an error in this program. [1]
(b) When correcting the command, explain the two bounds that should be used to choose a valid question pointer. [2]
Warehouse robot
(a) If the first random aisle is closed, the program loops back and generates another aisle number. [1]
(b) Aisle 6 remains within the range of RANDOM(1,9). Each new random generation can therefore produce 6 again, including several times in succession. [2]
Museum quiz array
(a) Pointer 25 causes an error because an array numbered 0 to 24 has no element at index 25. [1]
(b) The correct lower bound is 0 and the correct upper bound is 24. These bounds allow every valid array position, including question 0, to be selected. [2]
Everything you need to excel in your exams