Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow) - AQA - GCSE Computer Science - Question 9 - 2021 - Paper 1
Question 9
Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the... show full transcript
Worked Solution & Example Answer:Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow) - AQA - GCSE Computer Science - Question 9 - 2021 - Paper 1
Step 1
Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow).
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Initial Position: The robot starts at the square denoted by the ↑, facing upwards.
Execute Forward(2): The robot moves up 2 squares:
From (1, 1) to (0, 1) then to moving beyond the grid limit at (-1, 1). The path is drawn up to (0, 1).
Execute TurnLeft(): The robot turns left to face west.
Execute Forward(1): The robot moves left to (0, 0).
Execute TurnRight(): The robot turns right to face north again.
Execute Forward(1): The robot moves back up to (1, 0).
Final Path:
The path on the grid can be depicted as follows:
1 . . . . .
. . . . .
→ . . . .
Where the robot's journey is marked on the grid.
Step 2
Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow). If a square is black then it contains an object.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Initial Position: The robot starts at the square denoted by the ↑. Let's assume the position coordinates (1, 1).
Execute WHILE ObjectAhead() = true: Start the loop if there is an object straight ahead (upward).
Execute TurnLeft(): If there is an object ahead, the robot turns left (now facing west).
Execute IF ObjectAhead() = true THEN: Check if there is an object ahead:
If yes, it then executes TurnRight() (turns from west to north).
It executes another TurnRight() (now facing east).
Execute ENDIF: Finalizing conditions and actions.
Execute Forward(1): Moves to the east (if open).
Execute ENDWHILE: Returns to checking condition for the loop again.
Execute Forward(1): Finally, moves one square forward.
Final Path:
The path on the grid can be depicted as follows:
. . . . .
. . X . .
. . ↑ . .
Where 'X' denotes a square with an object the robot encounters.