OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Algorithms › Designing, creating and refining algorithms
Practise Pseudocode and flowcharts. 11 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.
Written for this site in the style of OCR exam questions. They are not taken from real past papers.
Question 1Easy5 marks
{fig} shows four flowchart symbols.
[object Object]
(a) Complete {table} by giving the name or purpose of each symbol in {fig}.[4]
[object Object]
(b) Describe the flowchart symbol that is used for a sub program.[1]
Show the answer and mark scheme
(a)
A: terminal / start or stop
B: input / output
C: decision / selection (with Yes / No branches)
D: process / calculation / assignment
(b)
a rectangle with (double) vertical lines inside each side / a process box with an extra line at each end
Question 2Medium6 marks
A theme park sells tickets online. Adult tickets cost £32 and child tickets cost £18. If a booking contains 5 or more tickets in total, the total price is reduced by 10%.
(a) Write an algorithm that:
asks the user to enter the number of adult tickets and the number of child tickets
calculates the total price, applying the discount when it is due
outputs the total price.
[5]
(b) State the total price for a booking of 3 adult tickets and 2 child tickets.[1]
Show the answer and mark scheme
(a)Answer:
adults = int(input("Number of adult tickets"))
children = int(input("Number of child tickets"))
total = adults * 32 + children * 18
if adults + children >= 5 then
total = total * 0.9
endif
print(total)
inputs the number of adult tickets and the number of child tickets
calculates adults × 32 + children × 18
checks whether adults + children is 5 or more
applies the 10% discount correctly (e.g. total × 0.9)
outputs the total price (after the discount check)
(a) Explain why this algorithm could be a security risk.[2]
(b) Refine the algorithm so that the user has a maximum of three attempts. If the password is still wrong after three attempts, the algorithm must output Account locked instead of Access granted. You must use either OCR Exam Reference Language or a high-level programming language that you have studied.[5]
Show the answer and mark scheme
(a)
the user has an unlimited number of attempts
so someone could keep guessing / use a brute-force attack until they find the password
(b)Answer:
correct = "Pa55word"
attempt = input("Enter password")
tries = 1
while attempt != correct AND tries < 3
print("Incorrect")
attempt = input("Enter password")
tries = tries + 1
endwhile
if attempt == correct then
print("Access granted")
else
print("Account locked")
endif
uses a counter that is initialised (to 0 or 1) before the loop
increments the counter each time a password is entered
loop stops when the password is correct OR three attempts have been made
outputs "Access granted" only when the password is correct
outputs "Account locked" after three incorrect attempts