Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)

70 questions · page 2 of 5 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
16
9608/23/O/N/20 · Question 5Oct/Nov 2020Paper 2324 marks
Loading question…
Question text

5
A hashtag is used on a social media network to make it easier to find messages with a specific
theme or content. A hashtag is a string consisting of a hash character ‘#’ followed by a number of
alphanumeric characters.
A message may contain several hashtag strings. A hashtag may be terminated by a space
character, the start of the next hashtag, or by the end of the message.
For example, the following message contains three hashtags:
"#Alarm34 is the result of #BatteryFailure in the #PowerModule"
The hashtags in this message are "#Alarm34", "#BatteryFailure" and "#PowerModule".
A program is being developed to monitor their use.
The program will include two global arrays each containing 10 000 elements:
•
A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").
•
A 1D array, TagCount, of type INTEGER storing a count of the number of times each hashtag
is used. The count value in a given element relates to the hashtag value stored in the element
in the TagString array with the corresponding index value.
A developer has started to define the modules. Module GetStart() has already been written.
Module
Description
•
Called with two parameters:
•
a message of type STRING
•
an integer giving the number of the required hashtag;
for example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
•
Returns an integer value representing the start position of
the hashtag in the message, or value −1 if that hashtag
does not exist
•
Called with a hashtag of type STRING
•
Copies the hashtag to the next free element of the
TagString array, and sets the corresponding element of
AddHashtag()
the TagCount array to 1
•
Returns FALSE if there are no unused elements in the
TagString array, otherwise returns TRUE
•
Called with a message of type STRING
•
Searches the message for hashtags using GetStart()
CountHashtag()
•
Returns a value representing the number of hashtags in the
message
•
Called with a hashtag of type STRING
•
Increments the value of the appropriate element in the
IncrementHashtag()
TagCount array if the hashtag is found
•
Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found
(a) Write pseudocode for the module AddHashtag().
…
…
…
…
…
…
…
…
…
…
…
…

17
9608/21/M/J/20 · Question 5May/June 2020Paper 2112 marks
Loading question…
Question text

5
(a) A 1D array, Directory, of type STRING is used to store a list of school internal telephone
numbers. There are 1000 elements in the array. Each element stores a single data item. The
format of each data item is as follows:
<Number><Name>
Number is a four-digit numeric string.
Name is a variable-length string.
For example:
"1024Collins Robbie"
The following pseudocode is an initial attempt at defining a procedure SortContacts()
that will perform a bubble sort on Directory. The array is to be sorted in ascending order of
Name.
Fill in the gaps to complete the pseudocode.
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
PROCEDURE SortContacts ()
DECLARE Temp : STRING
DECLARE FirstName, SecondName : STRING
DECLARE NoSwaps : …
DECLARE Boundary, J : INTEGER
…
Boundary
REPEAT
TRUE
NoSwaps
1 TO Boundary
FOR J
… (Directory[J], LENGTH(Directory[J]) – … )
FirstName
RIGHT(Directory[J + 1], LENGTH(Directory[J + 1]) – 4)
SecondName
IF FirstName …
THEN
Directory[J]
Temp
Directory …
Directory[J]
Temp
Directory[J + 1]
…
NoSwaps
ENDIF
ENDFOR
…
Boundary
UNTIL NoSwaps = TRUE
ENDPROCEDURE
[8]
(b) The pseudocode contains a mechanism designed to make this an efficient bubble sort.
Describe the mechanism and explain why it may be considered to be efficient.
…
…
…
…
…
…
…
…
…
… [4]

18
9608/21/M/J/20 · Question 6May/June 2020Paper 2119 marks
Loading question…
Question text

6
A company hires out rowing boats on a lake. The company has ten boats, numbered from 1 to 10.
The company is developing a program to help manage and record the hiring out process.
Hire information is stored in three global 1D arrays when a boat is hired out. Each array contains
10 elements representing each of the ten boats.
The three 1D arrays are summarised as follows:
Array
Data type
Description
Example data value
HireTime
STRING
"10:15"
The time the boat was hired out
Duration
INTEGER
30
The number of minutes of the hire
Cost
REAL
5.75
The cost of the hire
If an individual boat is not currently on hire, the corresponding element of the HireTime array will
be set to "Available".
The programmer has started to define program modules as follows:
Module
Description
•
Called with two parameters:
o a STRING value representing a time
AddTime()
o an INTEGER value representing a duration in minutes
•
Adds the duration to the time to give a new time
•
Returns the new time as a STRING
•
Called with a STRING value representing the time the
hire will start
•
Outputs the boat numbers that will be available for hire at
the given start time. A boat will be available for hire if it is
either:
ListAvailable()
o currently not on hire, or
o due back before the given hire start time
•
Outputs the number of each boat available
•
Outputs the total number of boats available or a suitable
message if there are none
•
Called with four parameters:
o an INTEGER value representing the boat number
o a STRING value representing the hire start time
o an INTEGER value representing the hire duration in
minutes
o a REAL value representing the cost of hire
RecordHire()
•
Updates the appropriate element in each array
•
Adds the cost of hire to the global variable DailyTakings
•
Converts the four input parameters to strings,
concatenated using commas as separators, and writes
the resulting string to the end of the existing text file
HireLog.txt
(a) Write pseudocode for the module ListAvailable().
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
19
9608/22/M/J/20 · Question 4May/June 2020Paper 227 marks
Loading question…
Question text

4
(a) Mustafa has developed the following pseudocode to generate ten random integers in the
range 1 to 100.
DECLARE Random : ARRAY [1:10] OF INTEGER
DECLARE Count, RNum : INTEGER
1 TO 10
FOR Count
INT(RAND(100)) + 1
Rnum
RNum
Random[Count]
ENDFOR
Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.
Rewrite the pseudocode so that there are no duplicated numbers in the list of random
numbers.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) The changes made to the pseudocode in part (a) were as a result of changes to the program
requirement.
Give the term used to describe changes made for this reason.
…

20
9608/22/M/J/20 · Question 5May/June 2020Paper 2219 marks
Loading question…
Question text

5
A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.
There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:
<Name>':'<EmailAddress>
Name and EmailAddress are both variable-length strings.
For example:
"Sharma Himal:[email protected]"
A function, GetName(), is part of the program that processes the array. A data item string will be
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.
(a) Use structured English to describe the algorithm for the function GetName().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
(b) (i)
The array is to be sorted using an efficient bubble sort algorithm. An efficient bubble sort
reduces the number of unnecessary comparisons between elements.
Describe how this could be achieved.
…
…
…
…
…

21
9608/23/M/J/20 · Question 2May/June 2020Paper 2313 marks
Loading question…
Question text

2
(a) A structure chart is often produced as part of a modular program design. The chart shows the
relationship between modules and the parameters that are passed between them.
Give two other features the structure chart can show.
Feature 1 …
…
Feature 2 …
…
[2]
(b) The following structure chart shows the relationship between three modules.
ModuleA()
ParW
ParX
ParZ
ModuleB()
ModuleC()
Parameter data types are:
ParW : REAL
ParX : INTEGER
ParZ : STRING
(i)
Write the pseudocode header for module ModuleB().
…
…
… [3]
(ii)
Write the pseudocode header for module ModuleC().
…
…
… [3]
(c) A student is developing an algorithm to count the number of times a given string,
SearchString, appears in a 2D array. The array, Item, consists of 100 elements organised
as 50 rows of 2 columns. SearchString could appear in any row or column.
The array is declared in pseudocode as follows:
DECLARE Item : ARRAY [1:50, 1:2] OF STRING
The structured English description of the algorithm is:
1.
SET Count to 0.
2.
Examine the first row of the array.
3.
IF column 1 element value is equal to SearchString, ADD 1 to Count.
4.
IF column 2 element value is equal to SearchString, ADD 1 to Count.
5.
REPEAT from step 3 for next row, UNTIL row is last row.
6.
OUTPUT a suitable message and Count.
Write pseudocode for the algorithm.
…
…
…
…
…
…
…
…
…

22
9608/23/M/J/20 · Question 4May/June 2020Paper 238 marks
Loading question…
Question text

4
A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.
There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:
<Name>':'<EmailAddress>
Name and EmailAddress are both variable-length strings.
For example:
"Wan Zhu:[email protected]"
A function, Extract(), is part of the program that processes the array. A string data item is
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.
(a) Write program code for the function Extract().
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) The original function, Extract(), needs to be modified to separate the name from the email
address. The calling program can then use both of these values.
Write, in pseudocode, the header for the modified subroutine. Explain the changes you have
made.
Subroutine header …

23
9608/21/O/N/19 · Question 4Oct/Nov 2019Paper 2111 marks
Loading question…
Question text

4
A student is developing a program to count how many times each character of the alphabet (A to Z)
occurs in a given string. Upper case and lower case characters will be counted as the same. The
string may contain non-alphabetic characters, which should be ignored.
The program will:
•
check each character in the string to count how many times each alphabetic character occurs
•
store the count for each alphabetic character in a 1D array
•
output each count together with the corresponding character.
(a) The student has written a structured English description of the algorithm:
1.
START at the beginning of the string
2.
SELECT a character from the string
3.
CONVERT the character to upper case
4.
CHECK whether the character is alphabetic and INCREMENT as required.
5.
REPEAT from step 2 until last character has been checked
6.
OUTPUT a suitable message giving the count of each alphabetic character
Step 4 above is not described in sufficient detail.
The student decides to apply a process to increase the level of detail given in step 4.
State the name of the process and use this process to write step 4 in more detail. Use
structured English for your answer.
Process …
Structured English …
…
…
…
…
…
[4]
(b) Write pseudocode to implement the program.
You should note the following:
•
InString contains the string to be checked. It has been assigned a value.
•
The elements of the array Result have all been initialised to zero.
•
The ASCII value of letter ‘A’ is 65.
You should assume the following lines of pseudocode have been written:
DECLARE InString : STRING
DECLARE Result : ARRAY [1:26] OF INTEGER
Declare any further variables you use. Do not implement the code as a subroutine.
Refer to the Appendix on pages 16–17 for the list of built-in functions and operators.
…
…
…
…
…
…
…
…
…

Advertisement
24
9608/21/O/N/19 · Question 6Oct/Nov 2019Paper 2121 marks
Loading question…
Question text

6
Account information for users of a library is held in one of two text files; UserListAtoM.txt and
UserListNtoZ.txt
The format of the data held in the two files is identical. Each line of the file is stored as a string that
contains an account number, name and telephone number separated by the asterisk character
('*') as follows:
<Account Number>'*'<Name>'*'<Telephone Number>
An example of one line from the file is:
"GB1234*Kevin Mapunga*07789123456"
The account number string may be six or nine characters in length and is unique for each
person. It is made up of alphabetic and numeric characters only.
An error has occurred and the same account number has been given to different users in the two
files. There is no duplication of account numbers within each individual file.
A program is to be written to search the two files and to identify duplicate entries. The account
number of any duplicate found is to be written to an array, Duplicates, which is a 1D array of
100 elements of data type STRING.
The program is to be implemented as several modules. The outline description of three of these is
as follows:
Module
Outline description
•
Initialise the global array Duplicates. Set all elements to the
ClearArray()
empty string.
•
Read each line from the file UserListAtoM.txt
Check whether the account number appears in file
•
UserListNtoZ.txt using SearchFileNtoZ()
FindDuplicates()
If the account number does appear then add the account
•
number to the array.
•
Output an error message and exit the module if there are more
duplicates than can be written to the array.
•
Search for a given account number in file UserListNtoZ.txt
SearchFileNtoZ()
If found, return TRUE, otherwise return FALSE
•
(a) State one reason for storing data in a file rather than in an array.
…
… [1]
(b) Write program code for the module SearchFileNtoZ().
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…

25
9608/22/O/N/19 · Question 3Oct/Nov 2019Paper 2211 marks
Loading question…
Question text

3
A student is developing a program to search through a string of numeric digits to count how many
times each digit occurs. The variable InString will store the string and the 1D array Result will
store the count values.
The program will:
•
check each character in the string to count how many times each digit occurs
•
record the count for each digit using the array
•
output the count for each element of the array together with the corresponding digit.
(a) The array Result is a 1D array of type INTEGER.
Write pseudocode to declare the array and to initialise all elements to zero.
…
…
…
…
…
… [3]
(b) Write the pseudocode for the program.
Declare any variables you use. Do not implement the code as a subroutine.
Refer to the Appendix on page 18 for the list of built-in functions and operators.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

26
9608/22/O/N/19 · Question 6Oct/Nov 2019Paper 2218 marks
Loading question…
Question text

6
A text file, StudentList.txt, contains a list of information about students in a school.
Each line of the file contains a reference, name and date of birth for one student. All the information
is held as strings and separated by the asterisk character ('*') as follows:
<Reference>'*'<Name>'*'<Date Of Birth>
An example of one line from the file is:
"G1234*Aleza Hilton*05062001"
The reference string may be five or eight characters in length and is unique for each student. It is
made up of alphabetic and numeric characters only.
A global 1D array, Leavers, contains the references of all students who have recently left the
school. The array consists of 500 elements of data type STRING. Unused elements contain the
empty string "".
A program is to be written to produce a new text file, UpdatedList.txt, containing information
only for students who are still attending the school.
The program is to be implemented as several modules. The outline description of three of these is
as follows:
Module
Outline description
•
Read each line from the file StudentList.txt
Check whether the Reference appears in the
•
array using SearchLeavers()
ProcessStudentList()
If the Reference does not appear then write the
•
line to the file UpdatedList.txt
Return the number of lines not copied.
•
•
Search for a given Reference in the array Leavers
SearchLeavers()
•
If the Reference is found, return TRUE, otherwise
return FALSE
•
Take two parameters: the name of an array and a
string.
CountTimes()
•
Count the number of elements that are the same as
the string. Return the count value.
(a) Write program code for the module SearchLeavers(). Declare any additional variables
you use.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…

27
9608/23/O/N/19 · Question 6Oct/Nov 2019Paper 2318 marks
Loading question…
Question text

6
A text file, Library.txt, stores information relating to a book collection. The file stores four
pieces of information about each book on separate lines of the file, as follows:
Line
n:
<Book Title>
Line
n + 1:
<Author Name>
Line
n + 2:
<ISBN>
Line
n + 3:
<Location>
Information is stored as data strings.
Information relating to two books is shown:
File line
Data
100
"Learning Python"
101
"Brian Smith"
102
"978-14-56543-21-8"
103
"BD345"
104
"Surviving in the mountains"
105
"C T Snow"
106
"978-35-17635-43-9"
107
"ZX001"
(a) (i)
A function, FindBooksBy(), will search Library.txt for all books by a given author.
The function will store the Book Title and Location in the array Result, and will
return a count of the number of books found.
Array Result is a global 2D array of type STRING. It has 100 rows and 2 columns.
Write pseudocode to declare the array Result.
…
…
… [3]
(ii)
Function FindBooksBy() will:
•
receive the Author Name as a parameter
•
search Library.txt for matching entries
•
store the Book Title and Location of matching entries in the Result array
•
return an integer value giving the number of books by the author that were found.
Write program code for the function FindBooksBy().
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

28
9608/21/M/J/19 · Question 1May/June 2019Paper 2120 marks
Loading question…
Question text

1
(a) (i)
Algorithms may be expressed using four basic constructs. One construct is sequence.
Complete the following table for two other constructs.
Construct
Pseudocode example
…
…
…
…
…
…
…
…
…
…
[4]
(ii)
Simple algorithms usually consist of input, process and output.
Complete the table by placing ticks (‘3’) in the relevant boxes.
Pseudocode statement
Input
Process
Output
SensorValue * Factor
Temp
WRITEFILE "LogFile.txt", TextLine
WRITEFILE "LogFile.txt", MyName & MyIDNumber
READFILE "AddressBook.txt", NextLine
[4]
(b) Program variables have values as follows:
Variable
Value
Title
"101 tricks with spaghetti"
Version
'C'
Author
"Eric Peapod"
PackSize
4
WeightEach
6.2
Paperback
TRUE
(i)
Evaluate each expression in the following table.
If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 16.
Expression
Evaluates to
MID(Title, 5, 3) & RIGHT(Author, 3)
INT(WeightEach * PackSize)
PackSize >= 4 AND WeightEach < 6.2
LEFT(Author, ASC(Version) - 65)
RIGHT(Title, (LENGTH(Author) – 6))
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for the following variables from part (b).
Variable
Data type
Title
Version
PackSize
WeightEach
Paperback
[5]
(c) White-box and black-box are two types of testing. In white-box testing, data are chosen to
test every possible path through the program.
Explain how data are chosen in black-box testing.
…
… [2]

Advertisement
29
9608/21/M/J/19 · Question 3May/June 2019Paper 2111 marks
Loading question…
Question text

3
(a) A student is developing an algorithm to search through a 1D array of 100 elements. Each
element of the array, Result, contains a REAL value.
The algorithm will output:
•
the average value of all the elements
•
the number of elements with a value of zero.
The structured English description of the algorithm is:
1.
SET Total value to 0
2.
SET Zero count to 0
3.
SELECT the first element
4.
ADD value of element to Total value
5.
IF element value is 0 then INCREMENT Zero count
6.
REPEAT from step 4 for next element, until element is last element
7.
SET Average to Total / 100
8.
OUTPUT a suitable message and Average
9.
OUTPUT a suitable message and Zero count
Write pseudocode for this algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
(b) The student decides to change the algorithm and implement it as a procedure, ScanArray(),
which will be called with three parameters.
ScanArray(AverageValue, ZeroCount, ArrayName)
ScanArray() will modify the first two parameters so that the new values are available to the
calling program or module.
Write the pseudocode procedure header for ScanArray().
…
…
…
…

30
9608/21/M/J/19 · Question 4May/June 2019Paper 2114 marks
Loading question…
Question text

4
The following pseudocode is a string handling function.
For the built-in functions list, refer to the Appendix on page 16.
FUNCTION Clean(InString : STRING) RETURNS STRING
DECLARE NewString : STRING
DECLARE Index : INTEGER
DECLARE AfterSpace : BOOLEAN
DECLARE NextChar : CHAR
CONSTANT Space = ' '
FALSE
AfterSpace
""
NewString
1 TO LENGTH(InString)
FOR Index
MID(InString, Index, 1)
NextChar
IF AfterSpace = TRUE
THEN
IF NextChar <> Space
THEN
NewString & NextChar
NewString
FALSE
AfterSpace
ENDIF
ELSE
NewString & NextChar
NewString
IF NextChar = Space
THEN
TRUE
AfterSpace
ENDIF
ENDIF
ENDFOR
RETURN NewString
ENDFUNCTION
(a) (i)
Complete the trace table by performing a dry run of the function when it is called as
follows:
Clean("X∇∇∇Y∇and∇∇Z")
Result
The symbol '∇' represents a space character. Use this symbol to represent a space
character in the trace table.
Index
AfterSpace
NextChar
NewString
[6]
(ii)
State the effect of the function Clean().
…
… [1]
(iii)
The pseudocode is changed so that the variable AfterSpace is initialised to TRUE.
Explain what will happen if the function is called as follows:
Clean("∇∇X∇∇∇Y∇and∇∇Z")
Result
…
…
…
… [2]
(b) The following pseudocode declares and initialises an array.
DECLARE Code : ARRAY[1:100] OF STRING
DECLARE Index : INTEGER
1 TO 100
FOR Index
""
Code[Index]
ENDFOR
The design of the program is changed as follows:
•
the array needs to be two dimensional, with 500 rows and 4 columns
•
the elements of the array need to be initialised to the string "Empty"
Re-write the pseudocode to implement the new design.
…
…
…
…
…
…
…
…
…
… [4]
(c) State the term used for changes that are made to a program in response to a specification
ch

Advertisement