Programming – A Level Computer Science (old syllabus, to 2021) (9608)
130 questions · page 1 of 9 · Clear filters
Question text
1
Part of the procedure InitVars() is shown:
PROCEDURE InitVars()
DECLARE Var1 : INTEGER
// daily rainfall
DECLARE Var2 : REAL
// the average wind speed
DECLARE Var3 : STRING
// the ID number of the weather station
ENDPROCEDURE
(a) Give a more meaningful identifier name for each of the following variables used by the
procedure.
Variable
New identifier name
Var1
Var2
Var3
[3]
(b) A function called ProcessVars() assigns values to variables as shown.
Variable
Value
HouseCount
12
Turnout2018
20.23
TidalRiskCategory
'C'
IsConservationArea
FALSE
StationLocationName
"Ocean Boulevard"
Some pseudocode expressions in the function are shown in the following table.
Complete the table by evaluating each expression and writing the answer in the Evaluates to
column.
If the expression is invalid, write “ERROR” in the Evaluates to column.
Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and operators.
Pseudocode expression
Evaluates to
LENGTH(HouseCount) > 6
MOD(INT(Turnout2018) * 3, 4)
ASC(TidalRiskCategory) + Turnout2018
IsConservationArea AND (HouseCount <= 50)
MID(StationLocationName, 1, 5) & " Eleven"
[5]
(c) The function header for ProcessVars() is:
FUNCTION ProcessVars(DataItem : REAL) RETURNS REAL
The following is an example of a parameter value passed to the function.
"L-MH-245,ManorHouse,N,F,230,12.34,0.98,12,N"
There is an error in the function header.
State the error and write the correct function header.
Error …
…
Correct function header …
…
[2]
(d) A programmer writes program code using an Integrated Development Environment (IDE).
Define the following three features of an IDE.
Breakpoints …
…
…
Report (watch) window …
…
…
Single stepping …
…
…
[3]
Question text
2
(a) The following pseudocode function counts the occurrences of a character in a string.
Line numbers are shown for reference only.
01
DECLARE Message : STRING
02
03
FUNCTION CharacterCount(Letter : CHAR) RETURNS INTEGER
04
05
DECLARE LetterCount, Index : INTEGER
06
DECLARE ThisChar : INTEGER
07
1
08
LetterCount
09
1 TO LENGTH(Message) - 1
10
FOR Index
LEFT(Message, Index, 1)
11
ThisChar
12
IF ThisChar = Letter
13
THEN
LetterCount + 1
14
LetterCount
15
ENDIF
16
ENDFOR
17
RETURN LetterCount
18
ENDFUNCTION
(i)
State the technical name of the iterative control structure used in this function.
… [1]
(ii)
Examine the pseudocode and write the answer in the table for each item.
Item
Answer
The scope of the variable Message is
The start and end line numbers of a selection structure
The identifier name of a user-defined function is
An arithmetic operator used in the function is
[4]
(b) Four lines of the pseudocode given in part (a) contain an error.
Identify the errors and write the correct pseudocode.
Line number for error 1 …
Correct pseudocode …
…
Line number for error 2 …
Correct pseudocode …
…
Line number for error 3 …
Correct pseudocode …
…
Line number for error 4 …
Correct pseudocode …
…
[4]
(c) A procedure, Frequency(), outputs the number of times each vowel occurs in a string.
The procedure will:
•
prompt and input a string
•
count the occurrence of each vowel in the string using a CASE structure
•
output each vowel with its count value.
You may assume that vowels are the upper-case or lower-case characters 'a', 'e', 'i',
'o', and 'u'.
Write pseudocode for the procedure Frequency().
Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and
operators.
…
…
…
…
…
Question text
3
An aeroplane carries cases.
A case is not allowed on the aeroplane if:
•
the total number of cases previously checked in for a flight is 300 or more
•
the weight of a case exceeds the maximum of 50 kilograms.
The following statements apply:
•
Each flight is identified by a five-character string variable FlightNo
•
Each case is identified by a three-character string variable CaseID
•
The weight of each case is represented by a two-digit numeric string variable CaseWeight
A text file, HOLD-CARGO.txt, stores data for cases on all flights. The format of each line of the file
is:
<FlightNo><CaseID><CaseWeight>
(a) A procedure, CheckWeight(), is required as follows:
•
take the flight number as parameter
•
output the list of case IDs for the flight that are not allowed on the aeroplane.
Write pseudocode for the procedure CheckWeight().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) A decision is made to use consta
Question text
4
A willow tree is a type of tree that grows at an angle. A 1D array, TreeAngle, has 20 elements of
integer type. Each element stores the angle of a willow tree measured in degrees.
A procedure called SafetyCheck() is required to:
•
check each tree angle in the array and count the number of trees that exceed the safe limit of
36 degrees
•
determine whether the count exceeds a maintenance limit stored in the global variable
MainTrigger, in which case a maintenance visit is required
•
output a suitable message if the count is less than or equal to MainTrigger, otherwise
output a message showing the number of times the safe limit was exceeded as follows:
"Maintain 10 trees".
(a) The SafetyCheck() procedure is written in pseudocode.
Complete the following pseudocode.
Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and operators.
PROCEDURE SafetyCheck()
DECLARE Count : INTEGER
DECLARE Index : INTEGER
CONSTANT TreeCount = 20
0
…
1 TO …
FOR Index
IF TreeAngle[Index] > …
THEN
Count + 1
Count
ENDIF
ENDFOR
IF … <= MainTrigger
THEN
OUTPUT "Maintenance not needed"
ELSE
OUTPUT "Maintain " & NUM_TO_STRING(Count) & " trees"
ENDIF
ENDPROCEDURE
[4]
(b) The TreeAngle array is changed to a 2D array that contains 20 rows and 2 columns of
integer numbers as follows:
•
The first column stores the integer reference number of the tree.
•
The second column stores the integer angle of the tree.
Study this example:
767 // tree reference
TreeAngle[15, 1]
12 // the angle of the tree
TreeAngle[15, 2]
A procedure, CheckTree(), is called with an integer parameter representing the tree’s
reference number.
The procedure will:
•
search the TreeAngle array for the reference number
•
when a match is found, prompt and input the angle of the tree, store the data in the
second dimension of the TreeAngle array, and then output a message if its safety
status has changed
•
when a match is not found, output the reference number and "No match".
Write program code for the procedure CheckTree().
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
5
(a) Module iteration and module selection are features of a structure chart.
State two other features that may be represented in a structure chart.
Feature 1 …
…
Feature 2 …
…
[2]
(b) Examine this structure chart of a booking system.
MakeBooking()
A
A
C
B
D
StoreBooking()
AmendDate()
MakePayment()
E
ExternalAuthorisation()
Complete the following table by writing the correct parameter letter (A, B, C, D or E) for each
parameter identifier.
Parameter identifier
Parameter letter
Quantity
BookingID
ItemCost
TotalCost
BookingDate
[5]
Question text
6
A geocode is a string that specifies a geographical location.
The string consists of two alphanumeric characters which are followed by:
•
the character '+'
•
two more alphanumeric characters
•
a comma
•
a description of the location.
Here is an example of an email message that contains two geocodes. The first is for Coventry in
the UK and the second is for Cambridge in the UK.
"This is my previous address 65+ER,CoventryUK.
I have now moved to my new location at 64+AA,CambridgeUK."
(a) A programmer decides to store the geocodes in a 1D array called Location. The array
contains 10 000 elements and unused array elements are initialised with the string "22+VV".
Write pseudocode to declare and initialise the array Location.
…
…
…
…
…
…
…
… [3]
(b) The following example pseudocode uses the function FindGeoCodeIndex() to search the
array Location for the index position of a given geocode.
DECLARE CodePosition : INTEGER
FindGeoCodeIndex(GeoCode)
CodePosition
IF CodePosition <> -1
THEN
OUTPUT Geocode & " found at " & NUM_TO_STRING(CodePosition)
ENDIF
Complete the program flowchart to represent the algorithm only for the function
FindGeoCodeIndex(). Variable declarations are not required in program flowcharts.
START
END
[4]
(c) The function RetrieveCode() will extract a geocode from an email message.
Here is a summary of the design requirements for this function.
Parameters
Returns
Example
"This is my
Message
•
•
A string containing the
A string containing the
previous address
email message
geocode
65+ER,CoventryUK."
•
An integer value
RetrieveCode(Message, 29)
containing the start
returns "65+ER,CoventryUK"
position of the geocode
in the message string
Assume that:
•
the integer value points to the start of a valid geocode
•
if a valid geocode is not at the end of the email message, it will be followed by a space
or a full stop.
Write program code for the function RetrieveCode().
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) Design and coding are stages of the program development cycle.
State two activities from each of these stages.
Design stage
Activity 1 …
Activity 2 …
Coding stage
Activity 1 …
Activity 2 …
[4]
(b) The following is part of a procedure to manage the stock in a shop:
100
PROCEDURE InitVars()
101
DECLARE Vs : STRING
//
program version
102
DECLARE Pe : REAL
//
stock item purchase price
103
DECLARE Exp : STRING
//
date when item expires
104
DECLARE S_lr: STRING
//
supplier ID
105
DECLARE Rp : REAL
//
low stock value
106
DECLARE OUT : BOOLEAN
//
any items in stock ?
…
180
ENDPROCEDURE
(i)
Give two reasons why the identifier names used in the procedure InitVars() are not
examples of good practice.
Reason 1 …
…
Reason 2 …
…
[2]
(ii)
Complete the following table by writing an appropriate identifier name for each of these
four lines in the procedure InitVars().
Line
Appropriate identifier name
102
103
105
106
[4]
(iii)
Line 101 of the procedure needs to be changed because:
•
the identifier should be declared as a fixed value that does not change during
program execution
•
the identifier name is not appropriate
•
the program version should be ver1.5.8
Write the new correct statement for line 101.
…
… [2]
(c) A program can store characters using either the ASCII or the Unicode character set.
Give two reasons why Unicode is preferred to the ASCII character set for storing characters.
Reason 1 …
…
…
Reason 2 …
…
…
[2]
Question text
2
A café manager needs a program for a loyalty scheme. A customer is awarded one loyalty point
for each purchase.
When a customer has ten or more points, the customer is offered a free slice of cake.
(a) During the program design, a decision is made to store the loyalty data in a text file called
LOYALTY.txt. This file holds the membership number and total number of points for each
customer on a single line.
Part of the program will check whether a particular customer has enough points for a free
slice of cake.
Describe the algorithm for this part of the program using structured English.
…
…
…
…
…
…
…
…
…
…
… [5]
(b) In another part of the program, the following statements assign values to variables.
"15"
DayOfMonth
TRUE
IsMember
"22042001"
DOB
"Seanna"
Firstname
"Adamson"
Lastname
12
Points
Complete the table by writing the pseudocode expression that matches the description given
and the value that each expression evaluates to.
Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and
operators.
Description of expression
Pseudocode expression
Evaluates to
Evaluates to TRUE if
DayOfMonth is within the
first seven days
of the month
Concatenates the second
and third letters of
Firstname with the last
three letters of Lastname
Evaluates to TRUE if DOB
contains eight characters
Evaluates to TRUE if the
customer is a member and
has enough points for a free
slice of cake
[4]
(c) Another part of the loyalty scheme program will need to access additional files. A filename
contains a three-letter extension that represents its file type.
For example, the filename "thisfile.txt" has the extension "txt" and file type "Text".
The filename will always be in lower case.
A function GetFileType() returns a string containing the description of the file type.
The function uses selection constructs as follows:
FUNCTION GetFileType(Filename : STRING) RETURNS STRING
DECLARE FileExt : STRING
DECLARE FileType : STRING
RIGHT(Filename, 3)
FileExt
IF FileExt = "rtf"
THEN
"Rich text format"
FileType
ENDIF
IF FileExt = "csv"
THEN
"Comma separated values"
FileType
ENDIF
IF FileExt = "txt"
THEN
"Text"
FileType
ELSE
"Unknown"
FileType
ENDIF
RETURN FileExt
ENDFUNCTION
Rewrite the function as follows:
•
Replace the IF structures with a CASE structure.
•
Correct the logic error in the function.
Refer to the Appendix on pages 1
Question text
4
A global 1D array Flower represents the flowers in a field and is defined as follows:
•
The array contains 20 elements of type integer.
•
Each element of the array contains a number associated with each flower.
(a) A procedure, InitialiseArray(), initialises the array Flower by setting the value of each
element to –1.
Write pseudocode for the procedure InitialiseArray().
…
…
…
…
…
…
…
…
… [4]
(b) A procedure called RandomPath() assigns values to the array Flower to store a path
through the flowers in the fields as follows:
•
the first flower to be visited is flower number 10
•
randomly select the next flower to be visited between 1 and 20
•
store the index of the next flower to be visited in the current element of the array Flower
if the flower has not been visited
•
visit each flower only once
•
repeat until the path has been completed through all flowers.
An element of –1 indicates that a flower has not been visited.
Write program code for the procedure RandomPath().
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
5
The pseudocode for a procedure FormatYear() is written as follows:
PROCEDURE FormatYear(Year : INTEGER, UseSuffix : BOOLEAN)
DECLARE OutYear : STRING
CONSTANT SUFFIX1 = "BCE"
CONSTANT SUFFIX2 = "CE"
NUM_TO_STRING(Year)
OutYear
IF UseSuffix = TRUE
THEN
IF Year < 0
THEN
OutYear & SUFFIX1
OutYear
ELSE
OutYear & SUFFIX2
OutYear
ENDIF
ENDIF
OUTPUT OutYear
ENDPROCEDURE
(a) Draw a program flowchart to represent the algorithm for the module.
Variable and constant declarations are not required in program flowcharts.
[5]
(b) For each of the following tests, choose three values of the parameters Year and UseSuffix
that test three different aspects of the procedure FormatYear().
State the expected output in each case.
Test 1
Parameter
Value
Expected output
Year
UseSuffix
Test 2
Parameter
Value
Expected output
Year
UseSuffix
Test 3
Parameter
Value
Expected output
Year
UseSuffix
[6]
(c) (i)
Describe two features of black-box testing.
…
…
…
… [2]
(ii)
Describe two features of white-box testing.
…
…
…
… [2]
Question text
6
A geocode string consists of four characters that are followed by:
•
the character '+'
•
two more characters
•
a comma
•
a description of the location.
For example:
•
The geocode string for Cambridge, UK is "646A+6R,CambridgeUK".
•
The geocode string for Chicago, USA is "V9PG+3P,ChicagoUSA".
A program uses two 1D arrays to store data about the locations in which photographs were taken.
•
An array GeoCodeData contains a geocode string for each location. A geocode string is
added to this array if it does not exist in the array.
•
An array GeoCodeLog contains the first seven characters of the geocode string for each
photograph, followed by a space and the date when the photograph was taken. The date
format is DD/MM/YYYY.
For example, a photograph taken in Cambridge, UK on 21/12/2020 is represented as:
"646A+6R 21/12/2020"
Assume that:
•
both arrays contain 20 000 elements
•
new data is added to the next unused element
•
unused array elements are indicated by the string "AAAA+0A".
(a) A programmer has started to define the program module SearchLog().
Module
Description
•
takes the first seven characters of a geocode as a parameter
•
counts the number of times this parameter occurs in the array
GeoCodeLog
SearchLog()
•
extracts the date the last photograph was taken at the geocode location
•
returns a string formed by concatenating the count, a single space and
the date
Write pseudocode for the module SearchLog().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
(a) An algorithm contains the following steps:
1.
prompt and input a product number
2.
validate the product number
3.
save the validated product number to FILE_A.txt
(i)
Write the pseudocode statement for step 1.
…
… [2]
(ii)
State the purpose of FILE_A.txt.
…
… [1]
(b) State two benefits of creating program flowcharts when documenting a program.
1 …
…
2 …
…
[2]
(c) Draw one line from each technical term to its appropriate description.
Technical term
Description
Stores data of the same data type
Corrective maintenance
in memory
Amends an algorithm following
Array
identification of errors
Amends an algorithm in response
Adaptive maintenance
to specification changes
Shows parameters passed between
Structure chart
program modules
[3]
(d) The following pseudocode procedure, SetupVars(), initialises the variables used to check
the status of a product.
PROCEDURE SetupVars()
"CONCRETE-SLAB"
Description
"ELY"
Destination
200
Mileage
1
EndOfYear
20000
Limit
FALSE
Overdue
ENDPROCEDURE
Complete the table by evaluating each pseudocode expression.
If the expression is invalid, write “ERROR” in the Evaluates to column.
Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and
operators.
Pseudocode expression
Evaluates to
EndOfYear * Limit / Mileage
LENGTH(Description) / NUM_TO_STRING(Limit)
MOD(20, LENGTH(Destination))
(EndOfYear < 2) AND (Limit = 20000) AND NOT(Overdue)
MID(Description, 1, 5) & LEFT(Destination, 2)
& NUM_TO_STRING(Limit / 1000)
[5]
Question text
2
A company owns 50 cars that are available for hire. The cars are numbered from 1 to 50. The size
of a car can be small, medium, or large.
The following pseudocode procedure, SetOut(), takes as input the size of the car the customer
has requested for hire and outputs details of the cars that are available for hire for that size of car.
Line numbers are given for reference only.
Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and operators.
01
DECLARE Available : ARRAY[1:50] OF BOOLEAN
02
DECLARE CarSize : ARRAY[1:50] OF STRING
03
04
PROCEDURE SetOut(Size: STRING)
05
DECLARE Index : REAL
06
0 TO 50
07
FOR Index
08
IF Size = CarSize[Index] AND Available[Index] = "TRUE"
09
THEN
10
OUTPUT NUM_TO_STRING(Index) & ": " & Size & " Available"
11
ENDIF
12
ENDFOR
13
14
ENDPROCEDURE
(a) Complete the table by identifying four line numbers that contain errors and give the correct
pseudocode statement.
Line number
Correct pseudocode statement
[4]
(b) Study the pseudocode algorithm on page 4.
Describe the algorithm using structured English.
Do not use pseudocode or program code in your answer.
…
…
…
…
…
…
…
… [4]
(c) The function PayUsingAccount() is required to process a payment for hiring a car as
follows:
1.
The function takes two parameters with REAL data type:
•
Balance is the amount of money in the account
•
CostOfHire is the cost of hiring the car.
2.
If CostOfHire exceeds Balance, the rental is not authorised and FALSE is returned,
otherwise TRUE is returned.
Write pseudocode for the function PayUsingAccount().
…
…
…
…
…
…
…
…
…
Question text
3
The function AddressChecker() checks if an email address is in the format:
<user>@<host> • <domain>
The design requirements of the function are:
•
The <user> contains only lower-case characters.
•
The <domain> contains exactly three alphabetic characters.
AddressChecker() will use three functions as described in the following table.
Function
Description
Split()
•
Takes two parameters:
•
a STRING value containing the email address
•
a BOOLEAN value representing the required return value
•
Returns two different values:
•
a STRING containing <user> if the BOOLEAN parameter
value is TRUE
•
a STRING containing <domain> if the BOOLEAN
parameter value is FALSE
IsLowerCase()
•
Takes an element of the email address as a STRING
parameter
•
Returns a BOOLEAN value of TRUE if the string contains only
lower-case characters, otherwise returns FALSE
IsThreeLetter()
•
Takes the domain as a STRING parameter
•
Returns a BOOLEAN value of TRUE if the string consists of
exactly three alphabetic characters, otherwise returns FALSE
AddressChecker() will:
•
prompt and input an email address
•
check that the email address is valid
•
return the string "Invalid" if the email address does not meet the design requirements,
otherwise return the email address.
(a) Draw a program flowchart to represent the algorithm for the AddressChecker() function.
Variable declarations are not required in program flowcharts.
[6]
(b) The function AddressChecker() is changed to check a list of email addresses stored in a
text file.
The function’s header is changed as follows:
FUNCTION AddressChecker(Filename : STRING, StartLine : INTEGER,
LastLine : INTEGER) RETURNS BOOLEAN
Assume that:
•
The function is called with a valid filename of the text file.
•
The text file exists and contains at least one email address.
•
Each email address is stored in a separate line in the text file.
•
The function does not contain logical errors.
Give two reasons why the function may return an unexpected result.
Reason 1 …
…
Reason 2 …
…
[2]
(c) (i)
Explain what is meant by the term syntax error.
…
…
…
… [2]
(ii)
Give an example of a syntax error in program code.
Programming language …
Program code
…
…
…
… [1]
(d) The following
Question text
4
The following pseudocode contains a function that searches a text file for the string contained in
the parameter Match.
01 DECLARE MatchItems : ARRAY[1:100] OF STRING
10 FUNCTION Extract(FileName : STRING, Match : STRING,
Signal : INTEGER) RETURNS BOOLEAN
11
12
DECLARE FileLine : INTEGER
13
DECLARE Counter : INTEGER
14
DECLARE FileData, SubMatch : STRING
15
DECLARE Result : BOOLEAN
16
0
17
Counter
1
18
FileLine
FALSE
19
Result
20
21
OPENFILE FileName FOR READ
22
23
WHILE NOT EOF(FileName) AND FileLine <= 100
24
READFILE FileName, FileData
LEFT(FileData, LENGTH(Match))
25
SubMatch
26
IF SubMatch = Match
27
THEN
FileData
28
MatchItems[Counter]
Counter + 1
29
Counter
30
ENDIF
FileLine + 1
31
FileLine
32
ENDWHILE
33
34
CLOSEFILE FileName
35
IF Counter >= Signal
36
THEN
TRUE
37
Result
38
ENDIF
39
RETURN Result
40
41 ENDFUNCTION
(a) Complete the trace table when the function is called using this statement:
Extract("DATA.txt", "TG12367", 1)
Present
You may assume that the text file DATA.txt contains the following lines:
"XD43668#23/11/19#DSCP"
"TG12367#24/01/19#MAHA"
"HD44356#24/11/19#MAHA"
"TG12367#24/11/19#GHFI"
FileLine
Counter
LEFT(FileData,
SubMatch = Match
Result
LENGTH(Match))
[5]
(b) The function is changed as follows:
•
The statement on line 25 is changed to compare the last ten characters of FileData
and the parameter Match.
If the comparison is successful:
•
store the first seven characters of FileData in a global 1D array called Original
•
store the last four characters of FileData in a global 1D array called Backup
•
The count of the number of items stored in the array Backup is returned.
(i)
Rewrite the function header in pseudocode so that it meets the new requirements.
…
…
…
… [2]
(ii)
Rewrite the WHILE structure in pseudocode so that it meets the new requirements. The
WHILE structure is given here for reference.
23
WHILE NOT EOF(FileName) AND FileLine <= 100
24
READFILE FileName, FileData
LEFT(FileData, LENGTH(Match))
25
SubMatch
26
IF SubMatch = Match
27
THEN
FileData
28
MatchItems[Counter]
Counter + 1
29
Counter
30
ENDIF
FileLine + 1
31
FileLine
32
ENDWHILE
…
…
…
…
…
…
…
…
…
…