Computer Science (AS & A Level) · Oct / Nov 2021 · Paper 21 · Question 6
9618
As printed in the paper
The question as text
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. 11 6 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() (generates test data) • Called with three parameters of type INTEGER: ◦a row number ◦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
Read automatically from the paper; the printed page above is exact.
Show the answer and mark scheme
6(a)[5]
6(b)[8]
6(c)[6]
Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.

