Data types, records, arrays and abstract data types – A Level Computer Science (9618)
112 questions · page 8 of 8 · Clear filters
Question text
6
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 will 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 on 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 of the touch.
11
6
A program is needed to find the coordinates (the row and column) of the centre point. The centre
point on the diagram shown 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 decided to use global values CentreRow and CentreCol as coordinate
values for the centre point.
The programmer has started to define program modules as follows:
Module
Description
• Searches for the first row that has an array element set to 1
• Returns the index of that row (1 is the first row)
FirstRowSet()
• Returns −1 if there are no elements set to 1
• Searches for the last row that has an array element set to 1
• Returns the index of that row
LastRowSet()
• Returns −1 if there are no elements set to 1
• Searches for the first column that has an array element set to 1
• Returns the index of that column (1 is the first column)
FirstColSet()
• Returns −1 if there are no elements set to 1
• Searches for the last column that has an array element set to 1
• Returns the index of that column
LastColSet()
• Returns −1 if there are no elements set to 1
(a) Write efficient pseudocode for the module FirstRowSet().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
3
(a) A concert venue uses a program to calculate admission prices and store information about
ticket sales.
A number of arrays are used to store data. The computer is switched off overnight and data
has to be input again at the start of each day before any tickets can be sold. This process is
very time consuming.
(i)
Explain how the program could use text files to speed up the process.
…
…
…
…
…
… [2]
(ii)
State the characteristic of text files that allow them to be used as explained in part (a)(i).
…
… [1]
(iii)
Information about ticket sales will be stored as a booking. The booking requires the
following data:
•
name of person booking
•
number of people in the group (for example a family ticket or a school party)
•
event type.
Suggest how data relating to each booking may be stored in a text file.
…
…
…
… [2]
(b) A procedure Preview() will:
•
take the name of a text file as a parameter
•
output a warning message if the file is empty
•
otherwise output the first five lines from the file (or as many lines as there are in the file if
this number is less than five).
Write pseudocode for the procedure Preview().
…
…
…
…
…
…
…
…
…
Question text
5
A global 2D array Result of type INTEGER is used to store a list of exam candidate numbers
together with their marks. The array contains 2000 elements, organised as 1000 rows and
2 columns.
Column 1 contains the candidate number and column 2 contains the mark for the corresponding
candidate. All elements contain valid exam result data.
A procedure Sort() is needed to sort Result into ascending order of mark using an efficient
bubble sort algorithm.
Write pseudocode for the procedure Sort().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
6
The following diagram represents an Abstract Data Type (ADT) for a linked list.
A
C
D
E
Ø
The free list is as follows:
Ø
(a) Explain how a node containing data value B is added to the list in alphabetic sequence.
…
…
…
…
…
…
… [4]
(b) Describe how the linked list in part (a) may be implemented using variables and arrays.
…
…
…
… [2]
Question text
3
The following diagram represents an Abstract Data Type (ADT).
A
B
Dolphin
Cat
Fish
Elk
(a) Identify this type of ADT.
… [1]
(b) Give the technical term for the item labelled A in the diagram.
… [1]
(c) Give the technical term for the item labelled B in the diagram.
Explain the meaning of the value given to this item.
Term …
Meaning …
…
…
[2]
(d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.
Dolphin
Cat
Fish
Elk
[2]
Question text
5
(a) A student is learning about arrays.
She wants to write a program to:
•
declare a 1D array RNum of 100 elements of type INTEGER
•
assign each element a random value in the range 1 to 200 inclusive
•
count and output how many numbers generated were between 66 and 173 inclusive.
(i)
Write pseudocode to represent the algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(ii)
The student decides to modify the algorithm so that each element of the array will contain
a unique value.
Describe the changes that the student needs to make to the algorithm.
…
…
…
…
…
… [3]
(b) The following is a pseudocode function.
Line numbers are given for reference only.
01
FUNCTION StringClean(InString : STRING) RETURNS STRING
02
03
DECLARE NextChar : CHAR
04
DECLARE OutString : STRING
05
DECLARE Counter : INTEGER
06
""
07
OutString
08
1 TO LENGTH(InString)
09
FOR Counter
MID(InString, Counter, 1)
10
NextChar
LCASE(NextChar)
11
NextChar
12
IF NOT((NextChar < 'a') OR (NextChar > 'z')) THEN
OutString & NextChar
13
OutString
14
ENDIF
15
NEXT Counter
16
17
RETURN OutString
18
19
ENDFUNCTION
(i)
Examine the pseudocode and complete the following table.
Answer
Give a line number containing an example of an initialisation statement.
Give a line
Question text
6
A procedure CountVowels() will:
•
be called with a string containing alphanumeric characters as its parameter
•
count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
•
count and output the number of occurrences of the other alphabetic characters (as a single
total).
The string may contain both upper and lower case characters.
Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.
Write pseudocode for the procedure CountVowels().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…