Oxford Cambridge and RSA
Please write clearly in black ink. Do not write in the barcodes.
First name(s)
Last name
Centre number Candidate number
OCR is an exempt Charity
Turn over
Friday 27 May 2022 – Morning
AS Level Computer Science
H046/02 Algorithms and problem solving
Time allowed: 1 hour 15 minutes
INSTRUCTIONS
Use black ink.
Write your answer to each question in the space provided. If you need extra space use
the lined pages at the end of this booklet. The question numbers must be clearly shown.
Answer all the questions.
INFORMATION
The total mark for this paper is 70.
The marks for each question are shown in brackets [ ].
Quality of extended response will be assessed in questions marked with an asterisk (*).
This document has 16 pages.
ADVICE
Read each question carefully before you start your answer.
© OCR 2022 [601/5030/0]
DC (ST/CGW) 300547/6
*8322620926*
*H04602*
Do not use:
a calculator
2
© OCR 2022
Answer all the questions.
1 Ruhail owns ten different function rooms which can be hired by different business customers to
hold meetings. He would like a program to manage the booking process of each room.
Customers should be able to enter the date they want to hire a function room, and then a list
of available rooms will be displayed. Customers can then select which room they want to hire.
Customers can then enter their payment details which are then checked and then a confirmation
email is sent to the customer.
(a) Complete the structure diagram below to show the different component parts of the problem.
Function
rooms
Choose
room
Check
payment details
Check
payment
Check
availability
[4]
(b) Ruhail will make use of an Integrated Development Environment (IDE).
State the purpose of an IDE.
...................................................................................................................................................
.............................................................................................................................................. [1]
(c) State two different programming constructs and give an example of how Ruhail could use
each construct when creating his program code.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
3
Turn over
© OCR 2022
(d) Ruhail will test his program code to make sure that it works correctly.
State two test strategies that Ruhail could use.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
(e) Ruhail will make use of a software development life cycle methodology.
State two software development methodologies that Ruhail could consider using.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
(f) Ruhail has been told to make use of reusable components when creating his program code.
Explain two benefits of using reusable components when writing program code.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
4
© OCR 2022
2 Logan is writing a program for his customers to be able to buy his gym equipment. In the program,
once a customer has selected the items they want to buy, a procedure, checkDetails, will be
called. This procedure will check that the customer has input their telephone number and also
check that it is at least 11 characters long.
(a) Logan has written two possible versions of the procedure that could be used to achieve this.
Version One:
procedure checkDetails()
telephoneNo = input("Enter telephone number")
while (telephoneNo == "") or (telephoneNo.length < 11)
print("Error, please try again")
telephoneNo = input("Enter telephone number")
endwhile
endprocedure
Version Two:
procedure checkDetails()
telephoneNo = input("Enter telephone number")
if (telephoneNo == "") or (telephoneNo.length < 11) then
print("Error, please try again")
telephoneNo = input("Enter telephone number")
endif
endprocedure
(i) Explain why version one is more effective than version two at making sure that the
telephone number entered is at least 11 characters long.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
5
Turn over
© OCR 2022
(ii) As well as the procedure checkDetails, Logan would like to use additional procedures
to expand his program.
The program will be expanded to:
allow customers to be able to register an account by setting up a username and
password
allow registered users to be able to log-in with their registration details
allow customers, once logged in, to be able to add items that are in stock to their
online shopping basket.
State two other procedures that Logan could write to meet these requirements, and for
each one, state a suitable name and purpose.
Procedure 1:
Procedure Name: ..............................................................................................................
Purpose: ............................................................................................................................
...........................................................................................................................................
Procedure 2:
Procedure Name: ..............................................................................................................
Purpose: ............................................................................................................................
...........................................................................................................................................
[4]
(iii) When setting up the additional procedures in his program, Logan will use a mixture of
parameter passing by reference and by value.
State the difference between parameter passing by reference and parameter passing by
value.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
6
© OCR 2022
(b)* Logan will work in a team with five other programmers and together they will create the
programming code for the program.
Discuss how modularity can be used to allow the team of programmers to work effectively
together on the same program at the same time.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [9]
7
Turn over
© OCR 2022
3 Trudi would like to sort an array of numbers into order.
The numbers before they have been sorted can be seen here.
89 25 75 37 45
(a) Trudi will use a bubble sort to put these numbers into order from smallest to largest.
Show the first pass of the bubble sort. You should clearly show each comparison made.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]
8
© OCR 2022
(b) Trudi has written a procedure, bubbleSort.
01 procedure bubbleSort(numbers)
02 do
03 sorted = true
04 for count = 0 to numbers.length -2
05 if numbers[count] > numbers[count+1] then
06 temp = numbers[count+1]
07 numbers[count+1] = numbers[count]
08 numbers[count] = temp
09 sorted = false
10 endif
11 next count
12 until sorted == true
13 endprocedure
(i) Identify a line in the procedure bubbleSort where a decision is taken.
...........................................................................................................................................
...................................................................................................................................... [1]
(ii) Identify the name of the parameter used in the procedure bubbleSort.
...........................................................................................................................................
...................................................................................................................................... [1]
(iii) Describe the purpose of the temp variable in the procedure bubbleSort.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(iv) Describe the purpose of the sorted variable in the procedure bubbleSort.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
9
Turn over
© OCR 2022
4 Given the following procedure:
01 procedure generate(number)
02 a = 0
03 while number > 0
04 if number MOD 2 == 0 then
05 a = a + 2
06 print(a)
07 number = number – 2
08 else
09 a = a + 1
10 print(a)
11 number = number – 1
12 endif
13 endwhile
14 endprocedure
(a) Explain why = is used on line 11 of the procedure generate instead of ==.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
(b) State the values printed by the procedure generate when number = 8.
...................................................................................................................................................
.............................................................................................................................................. [1]
(c) State the values printed by the procedure generate when number = 7.
...................................................................................................................................................
.............................................................................................................................................. [1]
10
© OCR 2022
(d) Describe the purpose of the MOD operator on line 04 of the procedure generate.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
11
Turn over
© OCR 2022
5 A veterinary surgery uses a two dimensional array to store bookings for customers to bring in their
animal to see the vet. There are ten possible booking slots during each day.
An example of the two dimensional array is shown in Fig. 1.
The first column stores the booking slot number, ranging between 1 and 10.
The second column stores the time of the appointment.
The third column stores the customerID of the customer who has booked that slot.
1 9:00 5877RC
2 9:30 9655AS
3 10:00
4 10:30 8754TT
5 11:00
6 11:30 8745SD
7 13:00 9635GH
8 13:30
9 14:00 9874PL
10 14:30 9658SV
Fig. 1
If a customerID has been entered for a booking slot then the booking slot has been taken. If no
customerID has been entered then the booking slot is available for booking.
(a) When customers make an appointment they often ask for the first available booking slot.
Describe how a linear search could be used for this purpose.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
12
© OCR 2022
(b) A function findFirst, is used to find the first available appointment.
Write the function findFirst that will find the first available appointment and return the
booking slot number. If no appointments are available then the function should return "-1".
You should write your function using pseudocode or program code.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [7]
(c) When an available time slot has been found then a valid customerID must be entered to
confirm the booking.
This is checked by another function called checkCustomerID. This will return true if the
customerID is valid or false if the customerID is not valid.
State why a function would be used instead of a procedure for this purpose.
...................................................................................................................................................
.............................................................................................................................................. [1]
13
Turn over
© OCR 2022
6 Kylie buys used games consoles and then sells them to make a profit. She sells her products in
multiples of £5 such as £30, £55 and £95. Kylie only accepts £50, £20, £10 and £5 notes from her
customers.
Kylie has written an algorithm which will calculate the amount of change needed by stating how
many £20, £10 and £5 notes are needed.
The program should output the minimum number of notes required. For example if £35 change is
required then it should output 1 x £20 and 1 x £10 and 1 x £5.
01 total = input("Enter total price of goods")
02 paid = input("Enter amount paid”)
03 global change = paid – total
04 calculateChange()
05
06 procedure calculateChange()
07 twenty = 0
08 ten = 0
09 five = 0
10 while change >= 20 //Calculates number of £20 notes needed
11 twenty = twenty + 1
12 change = change – 20
13 endwhile
14 while change >= 10 //Calculates number of £10 notes needed
15 ten = ten + 1
16 change = change – 10
17 endwhile
18 while change >= 5 //Calculates number of £5 notes needed
19 five = five + 1
20 change = change – 5
21 endwhile
22 print("The amount of change you need is £" + str(change))
23 print("Total £20 Notes:" + str(twenty))
24 print("Total £10 Notes:" + str(ten))
25 print("Total £5 Notes:" + str(five))
26 endprocedure
(a) Describe how calculateChange() on line 04 is used differently to calculateChange()
on line 06.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
14
© OCR 2022
(b) When line 22 is run, it will always print:
The amount of change you need is £0
Explain why this error occurs when line 22 is run.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
(c) Explain why Kylie has used str on lines 22 to 25 in her algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
END OF QUESTION PAPER
15
© OCR 2022
ADDITIONAL ANSWER SPACE
If additional space is required, you should use the following lined page(s). The question number(s)
must be clearly shown in the margin(s).
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
16
© OCR 2022
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
Oxford Cambridge and RSA
Copyright Information
OCR is committed to seeking permission to reproduce all third-party content that it uses in its assessment materials. OCR has attempted to identify and contact all copyright holders
whose work is used in this paper. To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced in the OCR Copyright
Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download from our public website (www.ocr.org.uk) after the live examination series.
If OCR has unwittingly failed to correctly acknowledge or clear any third-party content in this assessment material, OCR will be happy to correct its mistake at the earliest possible
opportunity.
For queries or further information please contact The OCR Copyright Team, The Triangle Building, Shaftesbury Road, Cambridge CB2 8EA.
OCR is part of Cambridge University Press & Assessment, which is itself a department of the University of Cambridge.