Question 12
AQA Computer Science June 2020 Paper 1GCSE12 marks
On the specification
- 12.1
- 3.1 Fundamentals of algorithms3.2 Programming
- 12.2
- 3.1 Fundamentals of algorithms3.2 Programming
- 12.3
- 3.1 Fundamentals of algorithms3.2 Programming
- 12.4
- 3.1 Fundamentals of algorithms3.2 Programming
Question text
12 A developer has written a set of subroutines to control an array of lights. The lights are indexed from zero. They are controlled using the subroutines in Table 2. Table 2 Subroutine Explanation If the light at index n is on it is set to off. SWITCH(n) If the light at index n is off it is set to on. If the light at index (n+1) is on, the light at index n is also set to on. NEIGHBOUR(n) If the light at index (n+1) is off, the light at index n is also set to off. All the lights between index m and index n RANGEOFF(m, n) (but not including m and n) are set to off. Array indices are shown above the array of lights. For example, if the starting array of the lights is 1 2 3 off on off on Then after the subroutine call SWITCH(2) the array of lights will become 1 2 3 off on on on And then after the subroutine call NEIGHBOUR(0) the array of lights will become 1 2 3 on on on on Finally, after the subroutine call RANGEOFF(0, 3) the array of lights will become 1 2 3 on off off on 12.1 If the starting array of lights is 1 2 3 4 5 6 on off off on off off on What will the array of lights become after the following algorithm has been followed? a ← 2 SWITCH(a) SWITCH(a + 1) NEIGHBOUR(a - 2) Write your final answer in the following array [3 marks] 1 2 3 4 5 6 12.2 If the starting array of lights is 1 2 3 4 5 6 off off on off on on on What will the array of lights become after the following algorithm has been followed? FOR a ← 0 TO 2 SWITCH(a) ENDFOR b ← 8 RANGEOFF((b / 2), 6) NEIGHBOUR(b - 4) Write your final answer in the following array [3 marks] 1 2 3 4 5 6 12.3 If the starting array of lights is 1 2 3 4 5 6 off on off on off on off What will the array of lights become after the following algorithm has been followed? a ← 0 WHILE a < 3 SWITCH(a) b ← 5 WHILE b ≤ 6 SWITCH(b) b ← b + 1 ENDWHILE a ← a + 1 ENDWHILE Write your final answer in the following array [3 marks] 1 2 3 4 5 6 12.4 If the starting array of lights is 1 2 3 4 5 6 on on on on on on on Write an algorithm, using exactly three subroutine calls, that means the final array of lights will be 1 2 3 4 5 6 off off off off off off off You must use each of the subroutines SWITCH, NEIGHBOUR and RANGEOFF exactly once in your answer. If you do not do this you may still be able to get some marks. [3 marks]