Programming – A Level Computer Science (9618)
153 questions · page 3 of 11 · Clear filters
Question text
2
A program is being developed to calculate the pay of employees working for a company.
A function CalculateBonus() calculates bonus pay based on the value of sales.
Bonus pay is calculated as shown in the table.
Value of sales
Bonus pay
(in dollars)
(in dollars)
below 2000
0
between 2000 and 4000 inclusive
10
above 4000
100
A flowchart for the function CalculateBonus() has been designed.
START
Set BonusPay to 0
INPUT
ValueOfSales
Is
NO
ValueOfSales
> 4000 ?
YES
Is
NO
ValueOfSales
Set BonusPay to 10
> = 2000 ?
YES
Set BonusPay to 100
RETURN BonusPay
END
ĬÕĊ®Ġ´íÈõÏĪÅĊàú¸Ā×
,
,
(a) The flowchart contains logic errors.
One logic error is that BonusPay will not be set to 10 although the ValueOfSales input is
between 2000 and 4000 inclusive.
(i)
Explain why this error occurs.
…
… [1]
(ii)
Explain how this error could be corrected.
…
… [1]
(b) There are different ways to reduce the risk of errors when developing the new program, such
as the use of constants.
(i)
State a value that could be replaced by a constant in the function CalculateBonus()
… [1]
(ii)
Explain how the use of constants helps to reduce the risk of programming errors.
…
…
…
… [2]
(iii)
One other way that can reduce the risk of errors when writing the program is the use of
library routines.
Explain how library routines can reduce the risk of programming errors.
…
… [1]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊàü¸Ā×
,
,
(c) All the logic errors have been corrected, and the program has been coded.
Identify and describe two other types of error that the program could contain.
Type of error …
Description …
…
…
Type of error …
Description …
…
Question text
3
A student has been asked to create a simple guessing game program. This program will generate
a random integer value between 1 and 100. It will then repeatedly prompt the user to input an
integer value until they input the randomly generated value.
The student has written a structured English description:
step 1 – randomly generate an integer value between 1 and 100 inclusive
step 2 – prompt the user to input an integer value
step 3 – output an appropriate message if the value input was too high; then repeat from step 2
step 4 – output an appropriate message if the value input was too low; then repeat from step 2
step 5 – output an appropriate message if the value input was the same value that was randomly
generated; then end the program.
Write a pseudocode algorithm from this structured English description.
Assume no input validation is needed.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝúµþ×
Question text
4
Study the algorithm:
DECLARE Chars : ARRAY[1:4] OF CHAR
DECLARE I, J : INTEGER
DECLARE Key : CHAR
2
I
'D'
Chars[1]
'T'
Chars[2]
'H'
Chars[3]
'R'
Chars[4]
WHILE I <= 4
//Outer loop
Chars[I]
Key
I – 1
J
WHILE J >= 0 AND Chars[J] > Key
//Inner loop
Chars[J]
Chars[J + 1]
J – 1
J
ENDWHILE
Key
Chars[J + 1]
I + 1
I
ENDWHILE
(a) The outer loop structure used in the algorithm is not the most appropriate one to use.
State the type of loop structure that would be the most appropriate to use and justify why it is
the most appropriate.
Loop structure …
Justification …
…
[2]
ĬÙĊ®Ġ´íÈõÏĪÅĊßüµĀ×
,
,
(b) Complete the trace table by dry running the algorithm.
The first row has been completed.
Chars
I
Key
J
Chars[J]
[1]
[2]
[3]
[4]
2
'D'
'T'
'H'
'R'
[6]
ĬÛĊ®Ġ´íÈõÏĪÅĊßúµĀ×
Question text
7
A program is being developed to implement a customer loyalty scheme for a coffee shop.
The programmer has decided that the following data items need to be stored for each customer:
Data item
Description
customer ID
a unique six-digit string
an integer value that is increased by one for every cup of coffee the
points
customer orders
When a customer visits the shop and orders coffee, the scheme operates as follows:
•
The total number of points is increased by the number of coffees ordered.
•
If just one cup of coffee is ordered and the number of points goes above 10, then:
◦
the cup of coffee they have just ordered is given to them free of charge
◦
the number of points is reduced by 11.
•
If the order is for multiple coffees and the number of points goes above 10, then:
◦
they get one coffee free of charge for every 11 points
◦
the number of points is reduced by 11 for each free coffee.
For example, the:
•
customer currently has 9 points
•
customer orders 16 cups of coffee
•
total number of points now becomes 25
•
customer gets 2 free coffees and now has 3 points left.
The programmer has defined a program module that is called every time a customer places an
order:
Module
Description
•
called with two integer parameters:
◦
the number of coffees ordered
◦
CustomerOrder()
the current number of points
•
output a suitable message giving the number of free coffees
•
return a value for the new points total.
ĬÕĊ®Ġ´íÈõÏĪÅĊßù¶Ă×
,
,
(a) Write pseudocode for module CustomerOrder()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
3
An algorithm is designed to generate and output two unique random integers. Each integer value
is between –10 and 10 inclusive.
If both integers output are negative, a third random integer between 30 and 35 inclusive will be
generated and output.
Write pseudocode for this algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
7
A program is being developed to implement a customer loyalty scheme for a coffee shop.
Each customer has a unique customer ID starting at 10001 with this value increasing by one each
time a new customer joins the loyalty scheme.
For example, the third customer who joins the loyalty scheme is given the customer ID 10003
The loyalty scheme is limited to 1000 customers.
A customer is awarded a loyalty point every time they buy a coffee.
The programmer has decided to use a global 2D array Loyalty of type INTEGER. The array
Loyalty is made up of 1000 rows and 2 columns. Each row relates to one customer; column 1
contains the unique customer ID and column 2 contains the number of customer loyalty points.
Rows in the array Loyalty that are not currently being used have the value of Column 1 set to
99999
The array is sorted in ascending order by customer ID.
The programmer has defined a program module:
Module
Description
•
called with parameter of type INTEGER representing a customer ID
•
searches the Loyalty array for this customer ID
•
the search will stop as soon as the customer ID is found
FindCustomer()
•
the search should efficiently deal with the situation when the
customer ID is not stored in the Loyalty array
•
if the customer ID is found, return an integer value representing the
loyalty points, otherwise return -1
ĬÕĊ®Ġ´íÈõÏĪÅĊßúµĂ×
,
,
(a) Write efficient pseudocode for module FindCustomer()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
A program is being developed for the management of a sports centre.
(a) The programmer developing the software decides to use modules (procedures or functions)
and local variables. They also decide not to use global variables.
(i)
State two reasons why the programmer decides to use modules.
1 …
…
2 …
…
[2]
(ii)
State one difference between local and global variables.
…
… [1]
(iii)
State two benefits of using local variables.
1 …
…
2 …
…
[2]
(b) The pseudocode design contains a number of expressions.
Complete each pseudocode expression so that it evaluates to the value shown.
Refer to the insert for the list of pseudocode functions and operators.
Expression
Evaluates to
'D'
… (68)
2
… (04/02/2025)
FALSE
… TRUE
1.4
… ( … ("Court1.4Upper" , … , … ))
[5]
ĬÕĊ®Ġ´íÈõÏĪÅĊàú·þ×
,
,
(c) The table lists some of the variables used in the program.
Complete the table by writing the most appropriate data type for each variable.
Variable
Use of variable
Data type
stores how many members have used the sports
MemberCount
centre each day
TotalTakings
stores the total amount of money taken each day
stores the state of a booking for an exercise class;
BookingConfirmed
a booking is either confirmed or not confirmed
to calculate when to send an email with a birthday
MemberDOB
message to a member
[4]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊàü·þ×
Question text
3
A programmer has been asked to create a module RollDice() to simulate multiple rolls of a
dice. This module will be used as part of a program for a game.
The module will:
step 1 – take a positive integer parameter representing the number of times the dice will be rolled
step 2 – simulate one roll of the dice by generating a random integer between 1 and 6 inclusive
step 3 – output the integer generated
step 4 – repeat, as required from step 2
step 5 – calculate the average value of the random integers generated
step 6 – return the average value.
Write pseudocode for the module RollDice()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
ĬÛĊ®Ġ´íÈõÏĪÅĊßú¶þ×
Question text
4
A programmer is developing a new stock control program for a shop owner to produce sales
reports.
(a) A text file Sales.txt stores strings representing the number of items sold.
The file contains 52 lines, each representing the number of items sold in each week of the
year.
For example:
File line number
File data
1
"350"
2
"502"
3
"434"
49
"492"
50
"872"
51
"772"
52
"201"
The example shows that 502 items were sold in week 2.
The owner requires a module to output all week numbers where the number of items sold is
greater than 500.
Describe an algorithm that produces the required module.
Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
… [5]
ĬÙĊ®Ġ´íÈõÏĪÅĊÝü¶Ā×
,
,
(b) Once the program has been completed, it is tested using the walkthrough method.
Describe the walkthrough method and explain how it can be used to identify errors.
…
…
…
…
…
…
…
… [3]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝú¶Ā×
Question text
5
A module Parity() takes a string as a parameter. The parameter has the identifier BitString
and it represents a binary value.
The module will concatenate a single character to the end of BitString by applying one of the
two rules:
•
'0' if Bitstring contains an even number of 1s
•
'1' if Bitstring contains an odd number of 1s.
The modified value of BitString is then returned.
For example:
Parameter
String returned
Explanation
"0010010110"
"00100101100"
there are an even number of 1s in the string
passed to Parity() so a '0' is concatenated
to the end of BitString
"101010"
"1010101"
there are an odd number of 1s in the string
passed to Parity() so a '1' is concatenated
to the end of BitString
Write pseudocode for the module Parity()
Assume the parameter BitString can only contain the characters '0' and '1'
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ĬÙĊ®Ġ´íÈõÏĪÅĊàü¸þ×
,
,
…
…
…
…
…
…
Question text
6
Study the structure chart:
Main
M
P
Sub_A
Sub_B
V
R
X
W
T
U
Sub_Part1A
Sub_Part2A
Sub_Part3A
Sub_Part1B
Sub_Part2B
Some of the parameter data types are:
•
R and V are of type INTEGER
•
T is of type REAL
•
U is of type STRING
•
W is of type BOOLEAN.
Some of the modules in the structure chart are functions, others are procedures.
(a) Explain one difference between functions and procedures.
…
… [1]
(b) Write the pseudocode to define the module headers:
Sub_Part1A
…
…
Sub_Part2A
…
…
Sub_Part3A
…
…
[5]
ĬÙĊ®Ġ´íÈõÏĪÅĊÞü¸Ā×
,
,
(c) The structure chart uses the two symbols shown.
Complete the table to explain what each symbol means and how the relevant modules in the
structure chart are affected.
Symbol
Explanation
…
…
…
…
…
…
[3]
ĬÛĊ®Ġ´íÈõÏĪÅĊÞú¸Ā×
Question text
7
A program is being developed to implement a customer loyalty scheme for a coffee shop.
The programmer has decided that the following data items need to be stored for each customer:
Data item
Description
customer ID
a unique six-digit string
loyalty points
an integer value that depends on how often the customer visits the coffee shop
last visit date
the date the customer last visited the coffee shop
The programmer has defined a program module:
Module
Description
• called with two parameters:
1. loyalty points of type INTEGER
2. last visit date of type DATE
•
change the loyalty points:
increase by four if the last visit date and the current date are in the
UpdateVisit()
same month
otherwise increase by one
•
change the last visit date to the current date
•
the changed values must be available to the code that follows the call
to UpdateVisit()
(a) (i)
Write pseudocode for module UpdateVisit()
Assume the customer has made at least one previous visit.
…
…
…
…
…
…
…
…
…
…
…
…
…
[5]
ĬÕĊ®Ġ´íÈõÏĪÅĊÝùµĂ×
,
,
(ii)
The programmer decides to amend the UpdateVisit() module so that loyalty points
are further increased if the customer visits the coffee shop the same day of the week as
their last visit.
Write the pseudocode for this condition.
…
… [1]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÝûµĂ×
,
,
(b) A text file Loyalty.txt will be used to store the data items for the loyalty scheme.
The text file Loyalty.txt contains only one line of data for each customer.
Each data item is separated by a comma:
<CustomerID>,<LoyaltyPointsString>,<LastVisitDateString>
LastVisitDateString is always eight characters in length in the format: DDMMYYYY.
An example of how a line of data will be stored in the text file Loyalty.txt is:
"100123,132,05032025"
This example shows that the customer with an ID of 100123 had 132 loyalty points following
their last visit to the coffee shop on 05/03/2025.
If a customer visits the coffee sh
Question text
1
A program will calculate the tax payable based on the cost of an item.
Calculations will occur at many places in the program and these involve the use of one of three tax
rates.
Tax rate values represent a percentage. For example, a tax rate value of 5.23 represents 5.23%.
In this case, the tax payable on an item costing $100 would be $5.23.
Tax rate values are used at several places within the program. One example is given in pseudocode
as follows:
←
HighRate
FALSE
CASE OF ItemCost
← 3.75
<= 50 : TaxRate
// tax rate of 3.75%
← 5.23
<= 200 : TaxRate
// tax rate of 5.23%
← 6.25
> 200 : TaxRate
// tax rate of 6.25%
← TRUE
HighRate
ENDCASE
←
* TaxRate // tax payable
TaxPayable
ItemCost
(a) The pseudocode contains a logical error.
Identify the error and suggest a correction.
Error …
…
Correction …
…
[2]
(b) During the design of the program, tax rate values have been used wherever they are needed
as shown in the pseudocode example above. Tax rates do not change while the program runs.
(i)
Identify a more appropriate way of representing the tax rate values in the final program.
… [1]
(ii)
Describe the benefits of your answer to part (b)(i) with reference to this program.
…
…
…
…
…
… [3]
ĬÕĊ®Ġ´íÈõÏĪÅĊÞü·þ×
,
,
(c) Give the appropriate data type for the variables in the following table, as used in the
pseudocode:
Variable name
Data type
HighRate
TaxPayable
[2]
(d) The final CASE condition (> 200) in the pseudocode example could be replaced with a
keyword.
Give the keyword.
… [1]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÞú·þ×
Question text
2
A program uses three global integer variables HH, MM and SS to represent the current time in
hours, minutes and seconds using the 24-hour clock notation.
Midnight would be represented as 00:00:00 (HH:MM:SS). If the variables HH, MM and SS contained
the values 16, 30 and 10 respectively, then the time would be 16:30:10 or just after 4.30 in the
afternoon.
A procedure Tick() will be called every second.
The procedure Tick() will:
•
update the value in SS each time it is called
•
update the values in HH and MM as appropriate
•
call a procedure CheckAlarm() at the start of each minute
•
call a procedure NewDay() whenever the time reaches midnight.
Complete the pseudocode for procedure Tick().
PROCEDURE Tick()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ENDPROCEDURE
[6]
ĬÕĊ®Ġ´íÈõÏĪÅĊàü·Ā×
Question text
3
An algorithm will output the last three lines from a text file Result.txt
The lines need to be output in the same order as they appear in the file.
Assume:
•
Three variables LineX, LineY and LineZ will store the three lines. These are of type string
and all three variables have been initialised to an empty string.
•
The file exists and contains at least three lines.
(a) The algorithm to output the lines is expressed in eight steps.
Complete the steps.
1.
Open the file …
2.
Loop until …
3.
… and store in ThisLine
4.
Assign LineY to LineX
5.
Assign LineZ to LineY
6.
Assign ThisLine to LineZ
7.
After the loop, …
8.
Output LineX, LineY, LineZ
[4]
(b) Explain the purpose of steps 4, 5 and 6 in the algorithm from part (a).
…
…
… [1]
ĬÙĊ®Ġ´íÈõÏĪÅĊÝú¶þ×
,
,
(c) The requirement changes, and the algorithm will now output three lines from the file, starting
from a given line number.
The modified algorithm will be implemented as a function which will:
•
be called with an integer parameter representing the given line number
•
output three lines, starting at the given line
•
return TRUE if the 3 lines are output, or FALSE if it was not possible to output the 3 lines.
Describe the changes that need to be made to steps 2 to 8 of the algorithm given in part (a).
…
…
…
…
…
…
…
…
…
… [4]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝü¶þ×