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

34 questions · page 1 of 3 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
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]

2
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().
…
…
…
…
…
…
…
…
…
…
…
…
…
…

3
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.
…

Advertisement
4
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.
…
…
…
…
…

5
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.
…
…
…
…
…
…
…
…
…

6
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 …

7
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]

8
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().
…
…
…
…

Advertisement
9
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

10
9608/22/M/J/19 · Question 3May/June 2019Paper 228 marks
Loading question…
Question text

3
The following structure chart shows the relationship between three modules.
TopLevel
B
D
A
C
E
SubA
SubB
Parameters A to E have the following data types:
A, D : STRING
C
: CHAR
B, E : INTEGER
(a) (i)
Write the pseudocode header for module SubA().
…
…
… [3]
(ii)
Write the pseudocode header for module SubB().
…
…
… [3]
(b) Module hierarchy and parameters are two features that may be represented on a structure
chart.
State two other features than can be represented.
Feature 1 …
Feature 2 …
[2]
Question 4 begins on the next page.

11
9608/22/M/J/19 · Question 5May/June 2019Paper 229 marks
Loading question…
Question text

5
A student is learning about text files. She wants to write a program to count the number of lines in
a file.
(a) Use structured English to describe an algorithm she could use.
…
…
…
…
…
… [3]
(b) A procedure, CountLines(), is being written to count the number of lines in a text file. The
procedure will:
•
take a filename as a string parameter
•
count the number of lines in the file
•
output a single suitable message that includes the total number of lines.
Write pseudocode for the procedure CountLines().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

12
9608/23/M/J/19 · Question 1May/June 2019Paper 2317 marks
Loading question…
Question text

1
The following pseudocode searches for the longest run of identical characters in the array
Message.
DECLARE Message : ARRAY[1:100] OF CHAR
PROCEDURE Search()
DECLARE
Index : INTEGER
DECLARE
ThisChar : CHAR
DECLARE
ThisRun : INTEGER
DECLARE
LongRun : INTEGER
Message[1]
ThisChar
1
ThisRun
1
LongRun
2 TO 100
FOR Index
IF Message[Index] = ThisChar
THEN
ThisRun + 1
ThisRun
ELSE
Message[Index]
ThisChar
IF ThisRun > LongRun
THEN
ThisRun
LongRun
ENDIF
1
ThisRun
ENDIF
ENDFOR
OUTPUT "The longest run was " , LongRun
ENDPROCEDURE
(a) Draw a program flowchart to represent the procedure Search().
Variable and array declarations are not required in program flowcharts.
[6]
(b) (i)
Program variables have values as follows:
Variable
Value
MeltingPoint
180.5
Soluble
FALSE
Attempt
3
ProductName
"Mushroom Compost"
Version
'A'
ProductID
"BZ27-4"
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 18.
Expression
Evaluates to
STRING_TO_NUM(MID(ProductID, 3, 2)) + 4
INT(MeltingPoint / 2)
Soluble AND Attempt > 3
LENGTH(ProductID & NUM_TO_STRING(MeltingPoint))
RIGHT(ProductName, 4) & MID(ProductName, 5, 4)
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for the following variables from part (b)(i).
Variable
Data type
MeltingPoint
Soluble
Attempt
Version
ProductID
[5]

13
9608/23/M/J/19 · Question 2May/June 2019Paper 2315 marks
Loading question…
Question text

2
(a) A student is learning about arrays. She wants to write a program to:
•
search through a 1D array of 100 elements
•
count the number of elements that contain the string “Empty”
•
output the number of elements containing “Empty” together with a suitable message.
Use structured English to describe the algorithm she could use.
…
…
…
…
…
…
…
…
…
…
… [5]
(b) She uses the process of stepwise refinement to develop her algorithm.
Explain this process.
…
…
…
…
…
… [3]
(c) The student is learning about file handling.
She has been told that there are different file modes that can be used when opening a text
file. She wants to make sure that the existing contents are not deleted when the file is opened.
Identify two file modes she could use and describe their use.
Mode …
Description …
…
…
Mode …
Description …
…

Advertisement
14
9608/23/M/J/19 · Question 6May/June 2019Paper 2320 marks
Loading question…
Question text

6
A text file, StudentContact.txt, contains a list of names and telephone numbers of students
in a school. Not all students in the school have provided a contact telephone number. In this case,
their name will not be in the file.
Each line of the file is stored as a string that contains a name and telephone number, separated by
the asterisk character ('*') as follows:
<Name>'*'<TelNumber>, for example:
"Bill Smith*081234567"
A 1D array, ClassList, contains the names of students in a particular class. The array consists
of 40 elements of string data type. You can assume that student names are unique.
Unused elements contain the empty string "".
A program is to be written to produce a new text file, ClassContact.txt, containing student
names and numbers for all students in a particular class.
For each name contained in the ClassList array, the program will:
•
search the StudentContact.txt file
•
copy the matching string into ClassContact.txt if the name is found
•
write the name together with “*No number” into ClassContact.txt if the name is not found.
The program will be implemented as three modules. The description of these is as follows:
Module
Description
ProcessArray()
•
Check each element of the array:
Read the student name from the array
○
Ignore unused elements
○
Call SearchFile() with the student name
○
If the student name is found, call AddToFile() to
○
write the student details to the class file
If the student name is not found, call AddToFile()
○
to write a new string to the class file, formed as
follows:
<Name>“*No number”
•
Return the number of students who have not provided a
telephone number
SearchFile()
•
Search for a given student name at the start of each line
in the file StudentContact.txt:
If the search string is found, return the text line from
○
StudentContact.txt
If the search string is not found, return an empty
○
string
AddToFile()
•
Append the given string to a specified file, for example,
AddToFile(StringName, FileName)
(a) Write program code for the module SearchFile().
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
…
…
…
…
…
…
…
…
…
…
…
…

15
9608/21/M/J/18 · Question 1May/June 2018Paper 2114 marks
Loading question…
Question text

(a) A program stores data about hospital patients.
1
Give a suitable identifier name for each of the data items.
Description of data item
Suitable identifier name
The temperature of the patient
The temperature of the room
The patient identification number
The name of the nurse taking the measurement
[4]
Program variables have values as follows:
(b) (i)
Variable
Value
MyGreeting
"Happy Birthday"
MyInitial
'C'
AgeInYears
27
Weight
60.5
Married
TRUE
Children
TRUE
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 15.
Expression
Evaluates to
"Mon" & MID(MyGreeting, 10, 2)
AgeInYears + ASC(MyInitial)
INT(MyInitial)
MOD(Weight * 2, 10)
Married AND (NOT Children)
[5]
Programming languages support different data types.
(ii)
Give an appropriate data type for each of these variables from part (b)(i).
Variable
Data type
MyGreeting
MyInitial
AgeInYears
Weight
Married
[5]

Advertisement