Programming – A Level Computer Science (old syllabus, to 2021) (9608)

66 questions · page 1 of 5 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9608/21/M/J/20 · Question 1May/June 2020Paper 218 marks
Loading question…
Question text

1
(a) Complete this definition of the term algorithm.
An algorithm is a solution to a problem expressed as …
…
… [2]
(b) A program design includes the use of subroutines (functions and procedures).
Give three advantages of using subroutines in a program.
1 …
…
2 …
…
3 …
…
[3]
(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.
Term
Description
Checking that a program
Selection
performs as expected
A method for increasing the
Black-box testing
level of detail of an algorithm
To test a condition to determine
Stepwise refinement
the path of program execution
A method of executing certain
Iteration
lines of code more than once
[3]

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

2
(a) Three modules form part of a program for a car rental company. A description of the
relationship between the modules is summarised as follows:
Module name
Description
A customer will pay for each car rental either by bank card or by using their
RentCar()
account with the rental company.
Called with parameter HireCost, representing the cost of the rental.
PayByCard()
Returns a BOOLEAN value to indicate whether or not the card payment was
successful.
Called with parameters HireCost, AccountNumber, CurrentBalance
and AccountLimit.
•
Checks whether HireCost plus the CurrentBalance would exceed
PayByAccount()
the AccountLimit. If so, then the rental is not authorised.
•
If the rental is authorised, then the CurrentBalance is updated.
•
Returns a BOOLEAN value to indicate whether or not the rental was
authorised.
Draw a structure chart to show the relationship between the three modules and the
parameters passed between them.
[5]
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
To be a valid password, a string must:
•
be longer than 6 characters
•
contain at least one lower case letter
•
contain at least one upper case letter
•
contain at least one non-alphabetic character.
10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN
11
12
DECLARE Index : INTEGER
13
DECLARE StrLen : INTEGER
14
DECLARE NumUpper, NumLower : INTEGER
15
DECLARE NumNonAlpha : INTEGER
16
DECLARE NextChar : CHAR
17
0
18
NumUpper
0
19
NumLower
0
20
NumNonAlpha
21
LENGTH(InString)
22
StrLen
23
IF StrLen < 7
24
THEN
25
RETURN FALSE
26
ELSE
1 TO StrLen
27
FOR Index
MID(InString, Index, 1)
28
NextChar
29
IF NextChar >= 'a' AND NextChar <= 'z'
30
THEN
NumLower + 1
31
NumLower
32
ELSE
33
IF NextChar > 'A' AND NextChar <= 'Z'
34
THEN
NumUpper + 1
35
NumUpper
36
ELSE
NumNonAlpha + 1
37
NumNonAlpha
38
ENDIF
39
ENDIF
40
ENDFOR
41
ENDIF
42
43
IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1)
44
THEN
45
RETURN TRUE
46
ELSE
47
RETURN FALSE
48
ENDIF
49
50 ENDFUNCTION
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
The pseudocode does not work under all circumstances.
A dry run performed on the function Check(), with the string "crAsh99", produced the
following trace table.
The string is a valid password, but the pseudocode would return the value FALSE.
Trace
StrLen
Index
NextChar
NumUpper
NumLower
NumNonAlpha
table row
7
0
0
0
1
1
'c'
2
1
3
2
'r'
4
2
5
3
'A'
6
1
7
4
's'
8
3
9
5
'h'
10
4
11
6
'9'
12
2
13
7
'9'
14
3
15
(i)
Describe how the completed trace table may be used to identify the error in the
pseudocode. In your answer, refer to the trace table row number(s).
…
…
…
…
… [2]
(ii)
State the pseudocode line number that has to be changed to correct the error and write
the correct pseudocode for the complete line.
Line number …
Correct pseudocode …
…
[2]
(iii)
Rewrite

3
9608/21/M/J/20 · Question 3May/June 2020Paper 2115 marks
Loading question…
Question text

3
(a) A mobile phone provider has developed an account management program. The program
includes a procedure, AddCredit(). The procedure is called with two parameters, TopUp
and PhoneNum.
The relevant part of the identifier table and the program flowchart for the procedure are as
shown:
Identifier
Type
Description
TopUp
REAL
The amount of credit to be added
PhoneNum
STRING
The unique customer phone number
Balance
REAL
The current amount of credit
Multiple
REAL
The amount of credit bonus
Takes the phone number as a parameter and returns the current
GetBalance()
FUNCTION
balance
Takes the phone number and the new balance as parameters and
SetBalance()
PROCEDURE
updates the account with the new balance
START
Set Multiple
to 1
Set Balance to
GetBalance(PhoneNum)
Is
YES
Set Multiple to
Balance > 10 ?
1.25
NO
Is
YES
Set Multiple to
Balance > 5 ?
1.1
NO
Set TopUp to
TopUp * Multiple
SetBalance(PhoneNum, Balance + TopUp)
END
Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow
the algorithm represented by the flowchart. Declare any local variables used.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

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

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

6
9608/22/M/J/20 · Question 2May/June 2020Paper 2211 marks
Loading question…
Question text

2
(a) A structure chart is often produced as part of a modular program design. The chart shows the
hierarchy of modules and the sequence of execution.
Give two other features the structure chart can show.
Feature 1 …
…
Feature 2 …
…
[2]
(b) Six program modules implement part of an online shopping program. The following table
gives the modules and a brief description of each module:
Module
Description
Allows the user to choose a delivery slot, select items to be added to
Shop()
the basket and finally check out
ChooseSlot()
Allows the user to select a delivery time. Returns a delivery slot number
FillBasket()
Allows the user to select items and add them to the basket
Completes the order by allowing the user to pay for the items. Returns
Checkout()
a Boolean value to indicate whether or not payment was successful
Search()
Allows the user to search for a specific item. Returns an item reference
Adds an item to the basket. Takes an item reference and a quantity as
Add()
parameters
(i)
The online shopping program has been split into sub-tasks as part of the design process.
Explain the advantages of decomposing the program into modules. Your explanation
should refer to the scenario and modules described in part (b).
…
…
…
…
…
… [3]
(ii)
Complete the structure chart for the six modules described in part (b).
Shop()
[6]

7
9608/22/M/J/20 · Question 3May/June 2020Paper 227 marks
Loading question…
Question text

3
A navigation program includes a function, CheckCourse(). This function is called with a real
value, Course, and returns an integer value.
The identifier table and the program flowchart for the function are shown as follows:
Identifier
Type
Description
Course
REAL
The value passed to CheckCourse()
Adjust
INTEGER
The value returned by CheckCourse()
Check
INTEGER
A local variable
A function that is passed a REAL value representing the
Deviate()
FUNCTION
course and returns a REAL value representing the current
deviation
Alert()
PROCEDURE
A procedure that generates a warning
START
Set Check to integer
value of
Deviate(Course)
Set Adjust to 255
CASE OF
Check
–20 to –1
Set Adjust to 10
OTHERWISE
0
Set Adjust to 0
Alert()
1 to 20
Set Adjust to –10
RETURN Adjust
END
Write pseudocode to implement the function CheckCourse(). The pseudocode must follow the
algorithm represented by the flowchart. Declare any local variables used.
Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

8
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
9
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.
…
…
…
…
…

10
9608/22/M/J/20 · Question 6May/June 2020Paper 2221 marks
Loading question…
Question text

6
A company hires out rowing boats on a lake. The company has 17 boats numbered from 1 to 17.
Boats may be hired between 9:00 and 18:00, with a maximum hire duration of 90 minutes.
The company is developing a program to help manage and record the boat hire process.
The programmer has decided to store all values relating to hire time as strings. The program will
use a 24-hour clock format. For example:
Time (in words)
String value
"09:00"
Nine o’clock in the morning
"10:05"
Five minutes past ten o’clock in the morning
"14:50"
Ten minutes before three o’clock in the afternoon
The programmer has defined the first module as follows:
Module
Description
•
Takes two parameters:
StartTime: a STRING value representing a time as described
AddTime()
Duration: 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
(a) (i)
Write pseudocode for the module AddTime(). Assume both input parameters are valid.
Refer to the Appendix on page 19 for a built-in list of pseudocode functions and
operators.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

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

12
9608/23/M/J/20 · Question 3May/June 2020Paper 2310 marks
Loading question…
Question text

3
(a) Study the following pseudocode.
Delta(Plan, Actual)
Error
CASE OF Error
Steer − 10
> 10 : Steer
ZCount + 1
0 : ZCount
Steer + 10
< -10 : Steer
OTHERWISE OUTPUT "Unexpected Error"
ENDCASE
Draw a program flowchart to represent the pseudocode. Variable declarations are not
required in program flowcharts.
[5]
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
To be a valid password, a string must:
•
be longer than five characters
•
contain at least one numeric digit
•
contain at least one upper case letter
•
contain at least one other character (not a numeric digit or an upper case letter).
10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN
11
12
DECLARE Index : INTEGER
13
DECLARE StrLen : INTEGER
14
DECLARE NumUpper, NumDigit : INTEGER
15
DECLARE NextChar : CHAR
16
DECLARE NumOther : INTEGER
17
0
18
NumUpper
0
19
NumDigit
20
LENGTH(InString)
21
StrLen
22
IF StrLen < 6
23
THEN
24
RETURN FALSE
25
ELSE
1 TO StrLen - 1
26
FOR Index
27
// loop for each character
MID(InString, Index, 1)
28
NextChar
29
IF NextChar >= '0' AND NextChar <= '9'
30
THEN
NumDigit + 1 // count digits
31
NumDigit
32
ELSE
33
IF NextChar >= 'A' AND NextChar <= 'Z'
34
THEN
NumUpper + 1 // count upper case
35
NumUpper
36
ENDIF
37
ENDIF
38
ENDFOR
39
ENDIF
40
StrLen – (NumDigit – NumUpper)
41
NumOther
42
IF NumDigit >= 1 AND NumUpper >= 1 AND NumOther >= 1
43
THEN
44
RETURN TRUE
45
ELSE
46
RETURN FALSE
47
ENDIF
48
49 ENDFUNCTION
The pseudocode does not work under all circumstances.
The function was dry run with the string "1234AP" and the following trace table was
produced. The string is an invalid password, but the pseudocode returned the value
TRUE.
Trace
StrLen
Index
NextChar
NumUpper
NumDigit
NumOther
table row
6
0
0
1
1
'1'
2
1
3
2
'2'
4
2
5
3
'3'
6
3
7
4
'4'
8
4
9
5
'A'
10
1
11
3
12
(i)
The pseudocode algorithm contains two errors.
State how the given trace table indicates the existence of each error.
Error 1 …
…
…
…
Error 2 …
…
…
…
[2]
(ii)
Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.
Line number for error 1 …
Correct pseudocode …
…
Line number for error 2 …
Correct pseudocode …
…

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

Advertisement
14
9608/23/M/J/20 · Question 5May/June 2020Paper 2336 marks
Loading question…
Question text

5
A company hires out rowing boats on a lake. The company has 20 boats, numbered from 1 to 20.
For safety reasons, the boats have to be serviced (checked and any damage repaired) regularly.
The company is developing a program to help manage the servicing of the boats.
Every time a boat is serviced, details are added at the end of the text file, ServiceLog.txt, as a
single line of information. Each boat is serviced before it is hired out for the first time.
The format of each line is as follows:
<BoatNumber><Date>
BoatNumber and Date are as follows:
•
BoatNumber is a two-digit numeric string in the range "01" to "20"
•
Date is an 8-digit numeric string in the format YYYYMMDD
The programmer has defined the first module as follows:
Module
Description
•
Called with a string parameter representing the BoatNumber
•
GetLastService()
Searches through the file ServiceLog.txt
•
Returns the date of the last service in the form "YYYYMMDD"
(a) Write pseudocode for the module GetLastService().
Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

15
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