Four separate subroutines have been written to control a robot - AQA - GCSE Computer Science - Question 9 - 2021 - Paper 1
Question 9
Four separate subroutines have been written to control a robot.
Forward(n) moves the robot n squares forward.
TurnLeft(t) turns the robot 90 degrees left.
TurnRig... show full transcript
Worked Solution & Example Answer:Four separate subroutines have been written to control a robot - 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
The robot executes the command 'Forward(2)', which moves it two squares forward. Starting at the position marked ↑, the robot first moves to square A, and then to square B. Therefore, the path drawn will mark squares A and B as the route taken by the robot.
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).
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
The robot will enter a loop because of the 'WHILE' condition considering objects in front. It will turn left, then check again. If there is an object, it will turn right twice and move forward by one square. Assuming it encounters black squares (indicating objects), it follows the path around the obstacles in squares A and B, eventually reaching square C after completing the commands given in the program.