Skip to main content
A-LevelComputer ScienceData types and structures9618/21 · Oct/Nov 2021 · Q619 Marks

A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows and 1280 columns. The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0 unless the user touches that part of the screen. Many array elements are set to 1 by a single touch of a finger or a stylus. The following diagram shows a simplified touchscreen. The dark line represents a touch to the screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements are shaded. The element shaded in black represents the centre point. [Diagram showing a grid with a shaded oval touch, a black shaded centre at row 6, col 11, with axes labeled 6 and 11] A program is needed to find the coordinates (the row and column) of the centre point. The centre point on the diagram above is row 6, column 11. Assume: • the user may only touch one area at a time • screen rotation does not affect the touchscreen. The programmer has started to define program modules as follows: Module Description SetRow() • Called with three parameters of type INTEGER: (generates test • a row number data) • the number of pixels to be skipped starting from column 1 • the number of pixels that should be set to 1 • Sets the required number of pixels to 1 For example, SetRow(3, 8, 5) will give row 3 as in the diagram shown. SearchInRow() • Takes two parameters of type INTEGER: • a row number • a start column (1 or 1280) • Searches the given row from the start column (either left to right or right to left) for the first column that contains an element set to 1 • Returns the column number of the first element in the given row that is set to 1 • Returns –1 if no element is set to 1 SearchInCol() • Takes two parameters of type INTEGER: • a column number • a start row (1 or 800) • Searches the given column from the start row (either up or down) for the first row that contains an element set to 1 • Returns the row number of the first element in the given column that is set to 1 • Returns –1 if no element is set to 1

  1. (a)Write pseudocode to implement the module SetRow().[5]
  2. (b)The module description of SearchInRow() is provided here for reference. Module Description SearchInRow() • Takes two parameters of type INTEGER: • a row number • a start column (1 or 1280) • Searches the given row from the start column (either left to right or right to left) for the first column that contains an element set to 1 • Returns the column number of the first element in the given row that is set to 1 • Returns –1 if no element is set to 1 Write pseudocode to implement the module SearchInRow().[8]
  3. (c)The following new module is introduced: Module Description GetCentreCol() • Called with a row number as an INTEGER • Uses SearchInRow() to find the first and last columns in the given row which have an array element set to 1 • Returns the index of the column midway between the first and last columns • Returns –1 if no element is set to 1 Write pseudocode to implement the module GetCentreCol().[6]

This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2021). The mark or mark type is shown in brackets.

  1. [5] PROCEDURE SetRow(Row, SkipNum, SetNum : INTEGER)
  2. DECLARE Col : INTEGER
  3. // array is 1280 x 800
  4. FOR Col ← SkipNum + 1 TO SkipNum + SetNum
  5. Screen[Row, Col] ← 1
  6. NEXT Index
  7. ENDPROCEDURE
  8. ALTERNATIVE 1:
  9. FOR Col ← 1 TO SetNum
  10. Screen[Row, SkipNum + Col] ← 1
  11. NEXT Col
  12. ALTERNATIVE 2:
  13. WHILE SetNum > 0
  14. Screen[Row, SkipNum + SetNum] ← 1
  15. SetNum ← SetNum - 1
  16. ENDWHILE
  17. Mark as follows:
  18. 1 Procedure heading and ending including parameters
  19. 2 Declaration of local Integer for Col
  20. 3 Count-controlled loop with meaningful start number
  21. 4 correct stop number
  22. 5 Reference Screen Array element and set to 1 in a loop
  23. [8] FUNCTION SearchInRow(ThisRow, StartCol : INTEGER) RETURNS INTEGER
  24. DECLARE ThisCol, Step : INTEGER
  25. DECLARE Found: BOOLEAN
  26. // array is 1280 x 800
  27. Found ← FALSE
  28. ThisCol ← StartCol
  29. // first decide which way to search
  30. IF StartCol = 1 THEN
  31. Step ← 1
  32. EndCol ← 1281
  33. ELSE
  34. Step ← -1
  35. EndCol ← 0
  36. ENDIF
  37. WHILE ThisCol <> EndCol AND Found = FALSE
  38. IF Screen[ThisRow, ThisCol] <> 1 THEN
  39. ThisCol ← ThisCol + Step
  40. ELSE
  41. Found ← TRUE
  42. ENDIF
  43. ENDWHILE
  44. IF Found = FALSE THEN
  45. ThisCol ← -1
  46. ENDIF
  47. RETURN ThisCol
  48. ENDFUNCTION
  49. Mark as follows:
  50. 1 Interpreting StartCol parameter to determine direction of search
  51. 2 An attempt at searching both up and down
  52. 3 Conditional Loop / Count-controlled loop with use of ThisCol index
  53. 4 Using correct values for StartCol, EndCol and Step
  54. 5 Reference a Screen element and compare with 1 in a loop
  55. 6 If equal save column or immediately Return column in a loop
  56. 7 Return column number or -1
  57. Loop(s) terminate when element with value = 1 found
  58. Max 7 marks if function heading, including return type, and ending is incorrect or incomplete
  59. [6] FUNCTION GetCentreCol (ThisRow : INTEGER) RETURNS INTEGER
  60. DECLARE StartCol, EndCol, CentreCol : INTEGER
  61. StartCol ← SearchInRow(ThisRow, 1)
  62. IF StartCol = -1 THEN
  63. CentreCol ← StartCol
  64. ELSE
  65. EndCol ← SearchInRow(ThisRow, 1280)
  66. CentreCol ← INT((StartCol + EndCol)/2)
  67. ENDIF
  68. RETURN CentreCol
  69. ENDFUNCTION
  70. Mark as follows:
  71. 1 Declaration of local INTEGER for return value
  72. 2 Use SearchInRow() with correct parameters and check for -1
  73. 3 Use SearchInRow(ThisRow, 1) and SearchInRow(ThisRow, 1280)
  74. 4 Calculate centre column
  75. 5 Use of INT () function // use of DIV
  76. 6 Return -1 or centre value
  77. Max 5 marks if function heading, including return type, and ending is incorrect or incomplete

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Data types and structures, A-Level Computer Science (syllabus 9618). Structured question, 19 marks.
Source
A-Level Computer Science, Oct/Nov 2021 Paper 2 Variant 1, question 6.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep