Question 13
AQA Computer Science June 2022 Paper 1 (7516/1)AS9 marks
On the specification
- 13.1
- 3.1 Fundamentals of programming3.2 Fundamentals of data structures
- 13.2
- 3.3 Systematic approach to problem solving
Question text
13 This question adds further validation to the Skeleton Program. The subroutine SolvePuzzle asks the user to enter coordinates and a digit. The Skeleton Program is to be changed so that if the digit entered by the user already exists in the referenced row, column or sub-grid, the digit cannot be used. Figure 6 shows the numbers in the puzzle grid cells of puzzle1 when first loaded. Figure 6 12 3 4 5 6 7 8 9 |===.===.===|===.===.===|===.===.===| 1| 8 . . 5 | . . | . . 7 | | | | | 2| 9 . . | 5 . . 4 | . . | | | | | 3| 4 . 1 . | . 6 . | . . | |===.===.===|===.===.===|===.===.===| 4| . . | 7 . . | 1 . 6 . | | | | | 5| 1 . . | 4 . . 6 | . . 3 | | | | | 6| . 5 . 8 | . . 1 | . . | |===.===.===|===.===.===|===.===.===| 7| . . | . 1 . | . 4 . 9 | | | | | 8| . . | 2 . . 7 | . . 1 | | | | | 9| 2 . . | . . | 5 . . 6 | |===.===.===|===.===.===|===.===.===| What you need to do: Task 1 Write a new subroutine, DuplicateDigit, which takes PuzzleGrid, Row, Column and Digit as parameters. The subroutine should return True if the digit entered by the user is already present in the row, column or sub-grid of the cell the user has entered. Otherwise, the subroutine should return False. Task 2 Amend the subroutine SolvePuzzle so that it uses DuplicateDigit to check the user input and only allows the digit to be placed into the puzzle grid if the digit is not already present in the row, column or sub-grid of the cell the user has entered. If the digit is already present, an appropriate message should be given to the user. Task 3 Test that the changes you have made work by conducting the following test: • run your amended Skeleton Program • enter L • load puzzle1 • enter S • enter 178 • enter 819 • enter 124 • enter 989 • enter 555 Evidence that you need to provide Include the following evidence in your Electronic Answer Document. 13.1 Your PROGRAM SOURCE CODE for the entire subroutine DuplicateDigit and the entire subroutine SolvePuzzle. [8 marks] 13.2 SCREEN CAPTURE(S) showing the requested test described in Task 3. The SCREEN CAPTURE(S) need(s) to show the puzzle grid before and after the described test. [1 mark]