Data types, records, arrays and abstract data types – A Level Computer Science (9618)

112 questions · page 7 of 8 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
91
9618/22/O/N/22 · Question 7Oct/Nov 2022Paper 2218 marks
Loading question…
Question text

7
A teacher is designing a program to perform simple syntax checks on programs written by
students.
Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
•
Array ErrCode contains integer values that represent an error number in the range 1 to 800.
•
Array ErrText contains string values that represent an error description.
The following diagram shows an example of the arrays.
ErrCode
ErrText
Index
10
"Invalid identifier name"
1
20
"Bracket mismatch"
2
50
"Undeclared variable"
3
60
"Type mismatch in assignment"
4
…
999
500
<Undefined>
Note:
•
There may be less than 500 error numbers so corresponding elements in both arrays may be
unused. Unused elements in ErrCode have the value 999. The value of unused elements in
ErrText is undefined.
•
Values in the ErrCode array are stored in ascending order but not all values may be present,
for example, there may be no error code 31.
The teacher has defined two program modules as follows:
Module
Description
•
takes two parameters as integers:
○
a line number in the student’s program
○
an error number
•
searches for the error number in the ErrCode array:
OutputError()
○
if found, outputs the corresponding error description and the
line number, for example:
"Bracket mismatch on line 34"
○
if not found, outputs the line number and a warning, for
example:
"Unknown error on line 34"
SortArrays()
sorts the arrays into ascending order of ErrCode
(a) Write efficient pseudocode for module OutputError().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Write an efficient bubble sort algorithm in pseudocode for module SortArrays().
…

92
9618/23/O/N/22 · Question 4Oct/Nov 2022Paper 2310 marks
Loading question…
Question text

4
(a) A program contains a 1D array DataItem with 100 elements.
State the one additional piece of information required before the array can be declared.
…
… [1]
(b) A programmer decides to implement a queue Abstract Data Type (ADT) in order to store
characters received from the keyboard. The queue will need to store at least 10 characters
and will be implemented using an array.
(i)
Describe two operations that are typically required when implementing a queue.
State the check that must be carried out before each operation can be completed.
Operation 1 …
…
Check 1 …
…
Operation 2 …
…
Check 2 …
…
[4]
(ii)
Describe the declaration and initialisation of the variables and data structures used to
implement the queue.
…
…
…
…
…
…
…
…
…
…
… [5]

93
9618/23/O/N/22 · Question 7Oct/Nov 2022Paper 2317 marks
Loading question…
Question text

7
A teacher is designing a program to perform simple syntax checks on programs written by
students.
Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
•
Array ErrCode contains integer values that represent an error number in the range 1 to 800.
•
Array ErrText contains string values that represent an error description.
The following diagram shows an example of the arrays.
ErrCode
ErrText
Index
10
"Invalid identifier name"
1
20
"Bracket mismatch"
2
50
""
3
60
"Type mismatch in assignment"
4
...
999
<Undefined>
500
Note:
•
There are less than 500 error codes so corresponding elements in both arrays may be
unused. Unused elements in ErrCode have the value 999. These will occur at the end of the
array. The value of unused elements in ErrText is undefined.
•
Values in the ErrCode array are stored in ascending order but not all values may be present.
For example, there may be no error code 31.
•
Some error numbers are undefined. In these instances, the ErrCode array will contain a
valid error number but the corresponding ErrText element will contain an empty string.
The teacher has defined one program module as follows:
Module
Description
• Prompts for input of two error numbers
• Outputs a list of error numbers between the two numbers input
(inclusive) together with the corresponding error description
• Outputs a warning message when the error description is
missing as for error number 50 in the example
• Outputs a suitable header and a final count of error numbers
found
OutputRange()
Output based on the example array data above:
List of error numbers from 1 to 60
10
:
Invalid identifier name
20
:
Bracket mismatch
50
:
Error Text Missing
60
:
Type mismatch in assignment
4 error numbers output
(a) Write pseudocode for module OutputRange(). Assume that the two numbers input
represent a valid error number range.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
94
9618/21/M/J/22 · Question 4May/June 2022Paper 216 marks
Loading question…
Question text

4
A stack is created using a high-level language. Memory locations 200 to 207 are to be used to
store the stack.
The following diagram represents the current state of the stack.
TopOfStack points to the last value added to the stack.
Stack
Pointer
Memory
Value
location
200
201
202
203
'F'
TopOfStack
204
'C'
205
'D'
206
'E'
207
'H'
(a) Complete the following table by writing the answers.
Answer
The value that has been on the stack for the longest time.
The memory location pointed to by TopOfStack if three POP
operations are performed.
[2]
(b) The following diagram shows the current state of the stack:
Stack
Pointer
Memory
Value
location
200
201
202
'W'
TopOfStack
203
'Y'
204
'X'
205
'Z'
206
'N'
207
'P'
The following operations are performed:
POP
POP
PUSH 'A'
PUSH 'B'
POP
PUSH 'C'
PUSH 'D'
Complete the diagram to show the state of the stack after the operations have been
performed.
Stack
Pointer
Memory
Value
location
200
201
202
203
204
205
206
207
[4]

95
9618/21/M/J/22 · Question 5May/June 2022Paper 216 marks
Loading question…
Question text

5
Each line of a text file contains data organised into fixed-length fields as shown:
<Field 1><Field 2><Field 3>
An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to
output the corresponding values for Field 1 and Field 3.
Describe the algorithm needed.
Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]

96
9618/22/M/J/22 · Question 4May/June 2022Paper 229 marks
Loading question…
Question text

4
(a) A procedure LastLines() will:
•
take the name of a text file as a parameter
•
output the last three lines from that file, in the same order as they appear in the file.
Note:
•
Use local variables LineX, LineY and LineZ to store the three lines from the file.
•
You may assume the file exists and contains at least three lines.
Write pseudocode for the procedure LastLines().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) The algorithm in part (a) is to be amended. The calling program will pass the number of lines
to be output as well as the name of the text file.
The number of lines could be any value from 1 to 30.
It can be assumed that the file contains at least the number of lines passed.
Outline three changes that would be needed.
1 …
…
…

97
9618/22/M/J/22 · Question 8May/June 2022Paper 2219 marks
Loading question…
Question text

8
A program allows a user to save passwords used to log in to websites. A stored password is then
inserted automatically when the user logs in to the corresponding website.
A global 2D array Secret of type STRING stores the passwords together with the website domain
name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.
Unused elements contain the empty string (""). These may occur anywhere in the array.
An example of a part of the array is:
Array element
Value
Secret[27, 1]
"thiswebsite.com"
Secret[27, 2]
""
Secret[28, 1]
"thatwebsite.com"
Secret[28, 2]
""
Note:
•
For security, the passwords are stored in an encrypted form, shown as "" in the
example.
•
The passwords cannot be used without being decrypted.
•
You may assume that the encrypted form of a password will NOT be an empty string.
The programmer has started to define program modules as follows:
Module
Description
•
Takes two parameters:
○ a string
○ a character
Exists()
•
Performs a case-sensitive search for the character in the string
•
Returns TRUE if the character occurs in the string, otherwise
returns FALSE
•
Takes a password as a parameter of type string
Encrypt()
•
Returns the encrypted form of the password as a string
•
Takes an encrypted password as a parameter of type string
Decrypt()
•
Returns the decrypted form of the password as a string
Note: in a case-sensitive comparison, 'a' is not the same as 'A'.
(a) Write pseudocode for the module Exists().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

98
9618/23/M/J/22 · Question 5May/June 2022Paper 2312 marks
Loading question…
Question text

5
A program will store attendance data about each employee of a company.
The data will be held in a record structure of type Employee. The fields that will be needed are as
shown:
Field
Typical value
Comment
EmployeeNumber
123
A numeric value starting from 1
Name
"Smith,Eric"
Format: <last name>','<first name>
Department
"1B"
May contain letters and numbers
Born
13/02/2006
Must not be before 04/02/1957
Attendance
97.40
Represents a percentage
(a) (i)
Write pseudocode to declare the record structure for type Employee.
…
…
…
…
…
…
… [4]
(ii)
A 1D array Staff containing 500 elements will be used to store the employee records.
Write pseudocode to declare the Staff array.
…
… [2]
(b) There may be more records in the array than there are employees in the company. In this
case, some records of the array will be unused.
(i)
State why it is good practice to have a standard way to indicate unused array elements.
…
… [1]
(ii)
Give one way of indicating an unused record in the Staff array.
…
… [1]
(c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees
who have an Attendance value of 90.00 or less.
Write pseudocode for the procedure Absentees().
Assume that the Staff array is global.
…
…
…
…
…
…
…

Advertisement
99
9618/23/M/J/22 · Question 7May/June 2022Paper 238 marks
Loading question…
Question text

7
The following pseudocode represents an algorithm intended to output the last three lines as they
appear in a text file. Line numbers are provided for reference only.
10
PROCEDURE LastLines(ThisFile : STRING)
11
DECLARE ThisLine : STRING
12
DECLARE Buffer : ARRAY[1:3] OF STRING
13
DECLARE LineNum : INTEGER
1
14
LineNum
15
OPENFILE ThisFile FOR READ
16
17
WHILE NOT EOF(ThisFile)
18
READFILE Thisfile, ThisLine // read a line
ThisLine
19
Buffer[LineNum]
LineNum + 1
20
LineNum
21
IF LineNum = 4 THEN
1
22
LineNum
23
ENDIF
24
ENDWHILE
25
26
CLOSEFILE ThisFile
1 TO 3
27
FOR LineNum
28
OUTPUT Buffer[LineNum]
29
NEXT LineNum
30
ENDPROCEDURE
(a) There is an error in the algorithm. In certain cases, a text file will have at least three lines but
the output will be incorrect.
(i)
State how the output may be incorrect.
…
… [1]
(ii)
Describe the error in the algorithm and explain how it may be corrected.
Description …
…
…
…
Explanation …
…
…
…
[4]
(b) The original algorithm is implemented and sometimes the last three lines of the text file are
output correctly.
State the condition that results in the correct output.
…
… [1]
(c) Lines 20 to 23 inclusive could be replaced with a single pseudocode statement.
Write the pseudocode statement.
…
… [2]

100
9618/21/O/N/21 · Question 2Oct/Nov 2021Paper 2112 marks
Loading question…
Question text

2
(a) An algorithm to sort a 1D array into ascending order is described as follows:
•
move the largest value to the end
•
keep repeating until the array is sorted.
Apply the process of stepwise refinement to this algorithm in order to produce a more detailed
description.
Write the more detailed description using structured English. Your explanation of the
algorithm should not include pseudocode statements.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) The program flowchart shown describes a simple algorithm.
START
Set Count to 1
Set Flag to FALSE
Is Flag =
YES
FALSE AND
Count <= 5 ?
NO
ReBoot()
Set Count to Count + 1
Set Flag to Check()
YES
Is Flag =
FALSE ?
NO
Alert(27)
END
Write pseudocode for the simple algorithm shown on page 6.
…
…
…
…

101
9618/21/O/N/21 · Question 3Oct/Nov 2021Paper 2113 marks
Loading question…
Question text

3
(a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.
The operation of this queue may be summarised as follows:
•
The front of queue pointer points to the next item to be removed.
•
The end of queue pointer points to the last item added.
•
The queue is circular so that empty storage elements can be reused.
0
Frog
Front of queue pointer
1
Cat
2
Fish
3
Elk
End of queue pointer
4
5
6
7
(i)
Describe how “Octopus” is added to the given queue.
…
…
…
… [2]
(ii)
Describe how the next item in the given queue is removed and stored in the variable
AnimalName.
…
…
…
… [2]
(iii)
Describe the state of the queue when the front of queue and the end of queue pointers
have the same value.
…
… [1]
(b) Some operations are carried out on the original queue given in part (a).
(i)
The current state of the queue is:
0
Frog
1
Cat
2
Fish
3
Elk
4
5
6
7
Complete the diagram to show the state of the queue after the following operations:
Add “Wasp”, “Bee” and “Mouse”, and then remove two data items.
[3]
(ii)
The state of the queue after other operations are carried out is shown:
0
Frog
1
Cat
2
Fish
3
Front of queue pointer
Elk
4
Wasp
5
Bee
6
End of queue pointer
Mouse
7
Ant
Complete the following diagram to show the state of the queue after the following
operations:
Remove one item, and then add “Dolphin” and “Shark”.
0
1
2
3
4
5
6
7
[2]
(c) The queue is implemented using a 1D array.
Describe the algorithm that should be used to modify the end of queue pointer when adding
an item to the queue.
Your algorithm should detect any potential error conditions.
…
…
…
…
…
… [3]

102
9618/21/O/N/21 · Question 5Oct/Nov 2021Paper 2110 marks
Loading question…
Question text

5
The following data items will be recorded each time a student successfully logs on to the school
network:
Data item
Example data
"CJL404"
Student ID
"Lib01"
Host ID
"08:30, June 01, 2021"
Time and date
The Student ID is six characters long. The other two data items are of variable length.
A single string will be formed by concatenating the three data items. A separator character will
need to be inserted between items two and three.
For example:
"CJL404Lib01<separator>08:30, June 01, 2021"
Each string represents one log entry.
A programmer decides to store the concatenated strings in a 1D array LogArray that contains
2000 elements. Unused array elements will contain an empty string.
(a) Suggest a suitable separator character and give a reason for your choice.
Character …
Reason …
…
[2]
(b) The choice of data structure was made during one stage of the program development life
cycle.
Identify this stage.
… [1]
(c) A function LogEvents() will:
•
take a Student ID as a parameter
•
for each element in the array that matches the Student ID parameter:
◦ add the value of the array element to the existing text file LogFile
◦ assign an empty string to the array element
•
count the number of lines added to the file
•
return this count.
Write pseudocode for the function LogEvents().
…
…
…
…
…
…
…
…
…
…
…
…
…
…

103
9618/21/O/N/21 · Question 6Oct/Nov 2021Paper 2119 marks
Loading question…
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 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
• Called with three parameters of type INTEGER:
◦
a row number
SetRow()
◦
the number of pixels to be skipped starting from column 1
(generates test
◦
the number of pixels that should be set to 1
data)
• Sets the required number of pixels to 1
For example, SetRow(3, 8, 5) will give row 3 as in the diagram shown.
• 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)
SearchInRow()
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
• 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
SearchInCol()
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
(a) Write pseudocode to implement the module SetRow().
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) The module description of SearchInRow() is provided here for reference.
Module
Description
• Takes two parameters of type INTEGER:
◦
a row number
◦
a start column (1 or 1280)

Advertisement
104
9618/22/O/N/21 · Question 3Oct/Nov 2021Paper 2214 marks
Loading question…
Question text

3
A programmer is writing a program to help manage clubs in a school.
Data will be stored about each student in the school and each student may join up to three clubs.
The data will be held in a record structure of type Student.
The programmer has started to define the fields that will be needed as shown in the following
table.
Field
Typical value
Comment
StudentID
"CF1234"
Unique to each student
Email
"[email protected]"
Contains letters, numbers and certain symbols
Club_1
1
Any value in the range 1 to 99 inclusive
Club_2
14
Any value in the range 1 to 99 inclusive
Club_3
27
Any value in the range 1 to 99 inclusive
(a) (i)
Write pseudocode to declare the record structure for type Student.
…
…
…
…
…
…
… [3]
(ii)
A 1D array Membership containing 3000 elements will be used to store the student
data.
Write pseudocode to declare the Membership array.
…
… [2]
(iii)
Some of the elements of the array will be unused.
Give an appropriate way of indicating an unused array element.
…
… [1]
(iv)
Some students are members of less than three clubs.
State one way of indicating an unused club field.
…
… [1]
(b) A procedure GetIDs() will:
•
prompt and input the number of a club
•
output the StudentID of all the students who are members of that club
•
output a count of all students in the given club.
Write pseudocode for the procedure GetIDs().
…
…
…
…
…
…

105
9618/22/O/N/21 · Question 5Oct/Nov 2021Paper 2210 marks
Loading question…
Question text

5
A company has several departments. Each department stores the name, email address and the
status of each employee in that department in its own text file. All text files have the same format.
Employee details are stored as three separate data strings on three consecutive lines of the file.
An example of the first six lines of one of the files is as follows:
File line
Comment
1
First employee name
2
First email address
3
First employee status
4
Second employee name
5
Second email address
6
Second employee status
A procedure MakeNewFile() will:
•
take three parameters as strings:
○ an existing file name
○ a new file name
○ a search status value
•
create a new text file using the new file name
•
write all employee details to the new file where the employee status is not equal to the search
status value
•
count the number of sets of employee details that were in the original file
•
count the number of sets of employee details that were written to the new file
•
produce a summary output.
An example summary output is as follows:
File Marketing contained 54 employee details
52 employee sets of details were written to file NewMarketingList
(a) Write pseudocode for the procedure MakeNewFile().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement