Question 9

AQA Computer Science November 2021 Paper 1 (8520/1)GCSE12 marks

On the specification

9.1
3.1 Fundamentals of algorithms3.2 Programming
9.2
3.1 Fundamentals of algorithms3.2 Programming
9.3
3.1 Fundamentals of algorithms3.2 Programming
Question text

9 box The Algebraic Patent Sewing Machine is a programmable sewing machine that creates patterns on rows of cloth. It is controlled by writing programs that use the following subroutines: Subroutine Description start the sewing machine needle at the left-hand side gotoRow(n) of row n move the needle forward by n cells without move(n) producing a pattern produce shape s where s can be 'square' or shape(s) 'circle' and move the needle to the next cell returns True if the needle is at the end of the row or atEnd() False otherwise For example, if the cloth looks like this to begin with: The subroutine call gotoRow(2) will place the sewing machine needle at the point shown by the black cross: The subroutine call move(3) will move the sewing machine needle to the point shown by the black cross: The subroutine call gotoRow(1) will move the sewing machine needle to the point box shown by the black cross: The subroutine call shape('square') will draw the following pattern and move the sewing machine needle to the point shown by the black cross: And finally, the subroutine call shape('circle') will draw the following pattern and move the sewing machine needle to the point shown by the black cross: All of the previous positions of the sewing machine needle would result in the subroutine call atEnd() returning False, however in the following example atEnd() would return True: 9 1 box . Draw the final pattern after the following algorithm has executed. gotoRow(0) WHILE atEnd() = False shape('square') move(1) ENDWHILE gotoRow(1) shape('circle') move(1) IF atEnd() = True THEN gotoRow(2) ELSE move(1) ENDIF shape('square') You should draw your answer on the following grid. You do not need to show the position(s) of the needle in your answer. [4 marks] 9.2 Draw the final pattern after the following algorithm has executed. box This question uses the MOD operator. MOD calculates the remainder after integer division, for example 7 MOD 5 = 2. patterns ← ['circle', 'square', 'square', 'circle'] r ← 2 FOR k ← 0 TO 3 gotoRow(k MOD r) move(k + 1) shape(patterns[k]) ENDFOR You should draw your answer on the following grid. You do not need to show the position(s) of the needle in your answer. [4 marks] 9 3 box . Develop an algorithm, using either pseudo-code or a flowchart, to produce the pattern shown in Figure 9. To gain full marks your answer must make appropriate use of iteration. Figure 9 [4 marks]