Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)
118 questions · page 4 of 8
Question text
1
Each student at CIE University needs a printing account to print documents from university
computers.
The university is developing software to manage each student’s printing account and the printing
process.
(a) Developing the software will include the following activities.
Time in
Activity
Description
Predecessor
weeks
A
Identify requirements
1
-
B
Produce design
3
A
C
Write code
10
B
D
Test modules
7
B
E
Final system black-box testing
3
C, D
F
Install software
1
E
G
Acceptance testing
2
F
H
Create user documentation
2
F
(i)
Add the correct activities and times to the following Program Evaluation Review
Technique (PERT) chart for the software development.
Two activities and times have been done for you.
4
A
1
2
3
5
6
1
1
F
7
8
9
[6]
(ii)
State what is meant by the critical path in a PERT chart.
…
… [1]
(iii)
Identify and describe a project planning technique, other than a PERT chart.
…
…
…
… [2]
(b) When a student prints a document, a print job is created. The print job is sent to a print server.
The print server uses a queue to hold each print job waiting to be printed.
(i)
The queue is circular and has six spaces to hold jobs.
The queue currently holds four jobs waiting to be printed. The jobs have arrived in the
order A, B, D, C.
Complete the diagram to show the current contents of the queue.
Start Pointer
End Pointer
[1]
(ii)
Print jobs A and B are now complete. Four more print jobs have arrived in the
order E, F, G, H.
Complete the diagram to show the current contents and pointers for the queue.
[3]
(iii)
State what would happen if another print job is added to the queue in the status
in part (b)(ii).
…
… [1]
(iv)
The queue is stored as an array, Queue, with six elements. The following algorithm
removes a print job from the queue and returns it.
Complete the following pseudocode for the function Remove.
FUNCTION Remove RETURNS STRING
DECLARE PrintJob : STRING
IF … = EndPointer
THEN
RETURN "Empty"
ELSE
PrintJob
Queue[ … ]
IF StartPointer = …
THEN
…
StartPointer
ELSE
StartPointer
StartPointer + 1
ENDIF
RETURN PrintJob
ENDIF
ENDFUNCTION
[4]
(v)
Explain why the circular queue could not be implemented as a stack.
…
…
…
Question text
2
The number of cars that cross a bridge is recorded each hour. This number is placed in a circular
queue before being processed.
(a) The queue is stored as an array, NumberQueue, with eight elements. The function
AddToQueue adds a number to the queue. EndPointer and StartPointer are global
variables.
Complete the following pseudocode algorithm for the function AddToQueue.
FUNCTION AddToQueue(Number : INTEGER) RETURNS BOOLEAN
DECLARE TempPointer : INTEGER
CONSTANT FirstIndex = 0
CONSTANT LastIndex = …
EndPointer + 1
TempPointer
IF … > LastIndex
THEN
…
TempPointer
ENDIF
IF TempPointer = StartPointer
THEN
RETURN …
ELSE
TempPointer
EndPointer
…
NumberQueue[EndPointer]
RETURN TRUE
ENDIF
ENDFUNCTION
[5]
(b) Describe how a number is removed from the circular queue to be processed.
…
…
…
…
…
…
…
… [4]
(c) A queue is one example of an Abstract Data Type (ADT).
Identify three other Abstract Data Types.
1 …
2 …
3 …
[3]
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]
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().
…
…
…
…
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
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.
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().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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]
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 …
…
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
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
(a) A stack contains the values 'red', 'blue', 'green' and 'yellow'.
Top of stack
yellow
green
blue
red
(i)
Show the contents of the stack in part(a) after the following operations.
POP()
PUSH('purple')
PUSH('orange')
[1]
(ii)
Show the contents of the stack from part(a)(i) after these further operations.
POP()
POP()
PUSH('brown')
POP()
PUSH('black')
[1]
(b) A queue is an alternative Abstract Data Type (ADT).
Describe a queue.
…
…
…
…
…
… [3]
Question text
2
A computer games club wants to run a competition. The club needs a system to store the scores
achieved in the competition.
A selection of score data is as follows:
99, 125, 121, 97, 109, 95, 135, 149
(a) A linked list of nodes will be used to store the data. Each node consists of the data, a left
pointer and a right pointer. The linked list will be organised as a binary tree.
(i)
Complete the binary tree to show how the score data above will be organised.
RootPointer
The symbol ∅ represents a null pointer.
LeftPointer
RightPointer
99
97
125
∅
121
[5]
(ii)
The following diagram shows a 2D array that stores the nodes of the binary tree’s linked
list.
Add the correct pointer values to complete the diagram, using your answer from
part (a)(i).
RootPointer
Index LeftPointer
Data
RightPointer
0
99
0
1
125
2
121
3
97
FreePointer
4
109
5
95
6
135
7
149
8
[6]
(b) The club also considers storing the data in the order in which it receives the scores as a
linked list in a 1D array of records.
The following pseudocode algorithm searches for an element in the linked list.
Complete the six missing sections in the algorithm.
FUNCTION FindElement(Item : INTEGER) RETURNS …
… ← RootPointer
WHILE CurrentPointer … NullPointer
IF List[CurrentPointer].Data <> …
THEN
CurrentPointer ← List[ … ].Pointer
ELSE
RETURN CurrentPointer
ENDIF
ENDWHILE
CurrentPointer ← NullPointer
… CurrentPointer
ENDFUNCTION
[6]
(c) The games club is looking at two programming paradigms: imperative and object-oriented
programming paradigms.
Describe what is meant by the imperative programming paradigm and the object-oriented
programming paradigm.
(i)
Imperative …
…
…
…
…
… [3]
(ii)
Object-oriented …
…
…
…
…
… [3]
(d) Players complete one game to place them into a category for the competition. The games club
wants to implement a program to place players into the correct category. The programmer
has decided to use object-oriented programming (OOP).
The highest score that can be achieved in the game is 150. Any score less than 50 will not
qualify for the competition. Players will be placed in a category based on their score.
The following diagram shows the design for the class Player. This includes the properties
and methods.
Player
Sco
Question text
1
A company wants an online marking system for an examination.
(a) The following is a selection of data showing final marks.
36, 45, 21, 65, 66, 13, 54, 53, 34
A linked list of nodes will be used to store the data. Each node consists of the data, a left
pointer and a right pointer. The linked list will be organised as a binary tree.
(i)
Complete the binary tree to show how the data above will be organised.
RootPointer
The symbol Ø represents a
null pointer
LeftPointer
RightPointer
36
45
21
Ø
65
66
Ø
Ø
[5]
(ii)
The following diagram shows a 2D array that stores the nodes of the binary tree’s linked
list.
Add the correct pointer values to complete the diagram, using your answer from
part (a)(i).
RootPointer
Index
LeftPointer
Data
RightPointer
0
0
36
1
45
FreePointer
2
21
3
65
4
66
5
13
6
54
7
53
8
34
9
[6]
(b) The company wants to implement a program for the marking system. It will do this with
object-oriented programming (OOP).
Many candidates take the examination. Each examination paper is given a PaperID that is
made up of the centre (school) number followed by the candidate number.
Each examination paper is awarded a grade.
The following diagram shows the design for the ExaminationPaper class. This includes
the attributes and methods.
ExaminationPaper
FinalMark : INTEGER // maximum 2 digits, initialised to 0
Grade
: STRING // "Pass", "Merit", "Distinction"
// or "Fail", initialised to "Fail"
PaperID
: STRING // centre number followed by the
// candidate number, for example
// "ZZ00991001"
Create()
//
creates and initialises a new instance
//
of the ExaminationPaper class using
//
language-appropriate constructor
SetFinalMark()
//
checks that the mark parameter has a
//
valid value, if so, assigns it to
//
FinalMark
SetGrade()
//
sets Grade based on FinalMark
GetFinalMark()
//
returns FinalMark
GetGrade()
//
returns Grade
GetPaperID()
//
returns PaperID
(i)
The constructor receives the centre number and candidate number as parameter values
to create PaperID. Other properties are initialised as instructed in the class diagram.
Write program code for the Create() constructor method.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
… [5]
(ii)
Get and set methods are used to support the security and integrity of data in
object-oriented programming.
Explain how get and set methods are used to support security and integrity.
…
Question text
2
A stack is an Abstract Data Type (ADT).
(a) Tick (3) one box to show the statement that describes a stack data structure.
Statement
Tick (3)
Last in first out
First in first out
Last in last out
[1]
(b) A stack contains the values 20, 35, 43, 55.
55
Top of stack
43
35
20
(i)
Show the contents of the stack in part (b) after the following operations.
POP()
POP()
PUSH(10)
[1]
(ii)
Show the contents of the stack from part (b)(i) after these further operations:
POP()
PUSH(50)
PUSH(55)
POP()
PUSH(65)
[1]
(iii)
The stack is implemented as a 1D array, with eight elements, and given the identifier
ArrayStack.
The global variable Top contains the index of the last element in the stack, or −1 if the
stack is empty.
The function Push():
•
takes as a parameter an INTEGER value to place on the stack
•
adds the value to the top of the stack and returns TRUE to show that the operation
was successful
•
returns FALSE if the stack is full.
Write an algorithm in pseudocode for the function Push().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
Question text
4
(a) A program has sorted some data in the array, List, in ascending order.
The following binary search algorithm is used to search for a value in the array.
FALSE
01
ValueFound
LengthOfList - 1
02
UpperBound
0
03
LowerBound
FALSE
04
NotInList
05
06
WHILE ValueFound = FALSE AND NotInList = FALSE
ROUND((LowerBound + UpperBound) / 2)
07
MidPoint
08
09
IF List[LowerBound] = SearchValue
10
THEN
TRUE
11
ValueFound
12
ELSE
13
IF List[MidPoint] < SearchValue
14
THEN
MidPoint + 1
15
UpperBound
16
ELSE
MidPoint – 1
17
UpperBound
18
ENDIF
19
IF LowerBound > MidPoint
20
THEN
TRUE
21
NotInList
22
ENDIF
23
ENDIF
24
ENDWHILE
25
26
IF ValueFound = FALSE
27
THEN
28
OUTPUT "The value is in the list"
29
ELSE
30
OUTPUT "The value is not found in the list"
31
ENDIF
Note:
The pseudocode function
ROUND(Reall : REAL) RETURNS INTEGER
rounds a number to the nearest integer value.
For example: ROUND(4.5) returns 5 and ROUND(4.4) returns 4
(i)
There are four errors in the algorithm.
Write the line of code where an error is present and write the correction in pseudocode.
Error 1 …
Correction …
Error 2 …
Correction …
Error 3 …
Correction …
Error 4 …
Correction …
[4]
(ii)
A binary search is one algorithm that can be used to search an array.
Identify another searching algorithm.
… [1]
(b) The following is an example of a sorting algorithm. It sorts the data in the array ArrayData.
""
01
TempValue
02
REPEAT
TRUE
03
Sorted
0 TO 4
04
FOR Count
05
IF ArrayData[Count] > ArrayData[Count + 1]
06
THEN
ArrayData[Count + 1]
07
TempValue
ArrayData[Count]
08
ArrayData[Count + 1]
TempValue
09
ArrayData[Count]
FALSE
10
Sorted
11
ENDIF
12
ENDFOR
13
UNTIL Sorted = TRUE
(i)
Complete the trace table for the algorithm given in part (b), for the ArrayData values
given in the table.
ArrayData
Count
TempValue
Sorted
0
1
2
3
4
5
5
20
12
25
32
29
[4]
(ii)
Rewrite lines 4 to 12 of the algorithm in part (b) using a WHILE loop instead of a FOR
loop.
…
…
…
…
…
…
…