Question 1 Report
Fig. 1 shows a section of a game program that validates a move on a 10 by 10 board. The player enters a row number into row. The program should reject row numbers outside 1 to 10. A message is displayed when the entered row is invalid.
(a) Explain why the relational tests are joined with OR. [1]
(b) When row is 0, state the path followed. [1]
(c) When row is 10, state the path followed. [1]
(d) When row is 14, explain which relational test is true. [1]
(e) When the board is changed to 12 rows, write the amended invalid-row condition. [1]
The canteen's allergy checker compares a selected meal code with a restricted code held in restrictedMeal. The code chosen by a student is stored in mealCode. If the two values are equal, the program must display a message and call a subroutine that suggests an alternative meal.
(a) Explain the Boolean result when mealCode = "P17" and restrictedMeal = "P17". [1]
(b) When the codes are "P17" and "V04", state the result of mealCode = restrictedMeal. [1]
(c) When the codes are equal, write two commands that could form the THEN block. [2]
Game-board validation
OR is used because a row is invalid if it is below the minimum of 1 or above the maximum of 10. It cannot be both at once. [1]row is 0, row < 1 is true. The flowchart follows the true path to Invalid move. [1]row is 10, neither row < 1 nor row > 10 is true. It follows the false path to Make move. [1]row is 14, the true relational test is row > 10. [1]row < 1 OR row > 12 [1]Allergy checker
"P17", they are equal, so mealCode = restrictedMeal is true. [1]"P17" and "V04", they differ, so the equality test is false. [1]THEN block is:DISPLAY "Restricted meal selected"
CALL suggestAlternative()Everything you need to excel in your exams