1.
Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose
between a basic room or a premium room.
When a new booking is recorded, the details are entered into a program to validate the
values. The following criteria are checked:
• firstName and surname are not empty
• room is either “basic” or “premium”
• nights is between 1 and 5 (inclusive).
If any invalid data is found “NOT ALLOWED” is displayed.
If all data is valid “ALLOWED” is displayed.
i. Complete the following program to validate the inputs.
You must use either: OCR Ref Language or high level language
firstName = input(“Enter a first name”)
surname = input(“Enter a surname”)
room = input(“Enter basic or premium”)
nights = input(“Enter between 1 and 5 nights”)
stayComplete = False
[5 marks]
ii. Complete the following test plan to check whether the number of nights is
validated correctly.
Test data
Type of test Expected output
(number of nights)
2 ALLOWED
Boundary ALLOWED
Erroneous / Invalid NOT ALLOWED
[3]
2. Jack is writing a program to add up some numbers. His first attempt at the program is
shown.
a = input(“Enter a number”)
b = input(“Enter a number”)
c = input(“Enter a number”)
d = input(“Enter a number”)
e = input(“Enter a number”)
f = (a + b + c + d + e)
print(f)
Give two ways that the maintainability of this program could be improved.
[2]
3. Each member of staff that works in a restaurant is given a Staff ID. This is calculated
using the following algorithm.
01 surname = input(“Enter surname”)
02 year = input(“Enter starting year”)
03 staffID = surname + str(year)
04 while [Link] < 10
05 staffID = staffID + “x”
06 endwhile
07 print(“ID ” + staffID)
i. Define the term casting and give the line number where casting has been used
in the algorithm.
Definition
Line number
[2]
ii. Complete the following trace table for the given algorithm when the surname
“Kofi” and the year 2021 are entered.
You may not need to use all rows in the table.
Line
surname year staffID Output
number
01 Kofi
02 2021
[4]
4(a). The algorithm for one section of a vending machine program is shown in
pseudocode.
if money >= price then
venditem()
giveChange(money – price)
else
print("Error – not enough money inserted")
endif
i. Give the identifier of one variable used in the algorithm.
[1]
ii. State how many parameters are passed into the giveChange() subroutine.
[1]
(b). A vending machine has the following options available.
Item code Item name Price
A1 Crisps, bacon flavour £0.75
A2 Crisps, salted £0.75
B1 Chocolate bar £0.90
C1 Apple pieces £0.50
C2 Raisins £0.85
Users insert coins into the vending machine and then enter the two character item code
of their selection. If the user has inserted enough money, the vending machine will
release the chosen item and output any change required. If the user enters an invalid
item code then a suitable error message is displayed.
Draw the vending machine algorithm in the part above as a flowchart.
[5]
(c). When writing the program for the vending machine, maintainability was
considered.
i. Identify two ways that the program in the part above has been made more
maintainable.
1
2
[2]
ii. Give one additional way that the maintainability of the program can be improved.
[1]
(d). The vending machine is tested before it is released.
i. Explain the purpose of testing the vending machine.
[2]
ii. Describe the difference between iterative testing and final testing.
[2]
iii. Complete the following test plan for the vending machine.
Code Money
Expected result
entered inserted
B1 £1 Chocolate bar served, £0.10 change given
£0.85 Raisins served, no change given
C1 Error – not enough money inserted
C3 £0.75
[3]
5(a). OCR Tech is an online shop that sells electronics such as TVs and game
consoles.
An item is classified as "In demand" if OCR Tech have between 5 and 25 inclusive in
stock.
A program is written that allows the user to input the current stock level and output
whether the item is in demand or not.
stocklevel = input("Enter stock level")
if stocklevel >= 5 or =< 25 then
print(Not in demand)
else
print(In demand)
endif
The program contains syntax and logic errors.
Refine the program to correct the errors and write the refined version of the
program.
You must use either: OCR Exam Reference Language, or A high-level programming
language that you have studied
[5]
(b). The following flowchart shows an algorithm to calculate the price of an item during
a sale period.
i. Complete the following test plan for the algorithm.
Price input Test type Expected price output
50 Normal
100 Boundary
150 Normal
200 Boundary
250 Normal
[3]
ii. Rewrite the algorithm above.
You must use either: OCR Exam Reference Language, or A high-level
programming language that you have studied
[6]
6(a). A car dealership uses a computer system to record details of the cars that it has
for sale. Each car has a make, model, age and number of miles driven.
The car dealership only sells cars that have fewer than 10 000 miles and are 5 years old
or less.
i. Write an algorithm that will:
• ask the user to enter the number of miles and the age of a car
validate the input to check that only sensible values that are in the
•
given range are entered
output True if valid data has been entered or False if invalid data has
•
been entered.
[5]
ii. The validation routine from part (i) must be tested with normal, erroneous
and boundary test data.
Identify suitable test data for each type of test.
Miles Age
Normal
Erroneous
Boundary
[3]
iii. Identify when iterative testing is performed.
[1]
(b). Each car is given a star rating of 1 to 5, based on the age of the car and the
number of miles it has been driven. This rating is recorded in the computer system.
i. Define the term abstraction.
[1]
ii. Give one example of how abstraction has been used in the design of this star
rating system.
[1]
iii. Explain how authentication could be used as part of the defensive design
considerations for this computer system.
[2]
7(a). A teacher researches the length of time students spend playing computer games
each day.
The teacher writes a program to add up and print out the total number of minutes
student 2 played computer games over 5 days (Monday to Friday).
total = 0
total = total + minsPlayed[2,0]
total = total + minsPlayed[2,1]
total = total + minsPlayed[2,2]
total = total + minsPlayed[2,3]
total = total + minsPlayed[2,4]
print(total)
Refine the program to be more efficient. Write the refined version of the algorithm.
You must use either: OCR Exam Ref Language or high level programming language
[4]
(b). The program should only allow values from 0 to 300 inclusive as valid inputs. If
the data entered breaks this validation rule, an error message is displayed.
i. Complete the following program to output "Invalid input" if the data does not
meet the validation rule.
You must use either: OCR Exam Ref Language or high level programming
language
mins = input("Enter minutes played: ")
if mins < 0 ..................... mins ..................... then
..................... ("Invalid input")
endif
[3]
ii. Complete the following test plan for the program in (i)
Test data Test type Expected result
25 Normal Value accepted
Invalid input
Invalid
message displayed
Boundary
[3]
8(a). OCR Land is a theme park aimed at children and adults. Entrance tickets are sold
online. An adult ticket to OCR Land costs £19.99, with a child ticket costing £8.99. A
booking fee of £2.50 is added to all orders.
One ride in OCR Land has a minimum height of 140 cm to ride alone or 120 cm to ride
with an adult.
Create an algorithm that:
• asks the user to input the height of the rider, in centimetres
• if needed, asks if they are riding with an adult
• outputs whether or not they are allowed to ride
• repeats this process until 8 people have been allowed to ride.
[8]
(b). OCR Land keeps track of the size of queues on its rides by storing them in an array
with the identifier queuesize. It uses the following bubble sort algorithm to put these
queue sizes into ascending numerical order.
01 swaps = True
02 while swaps
03 swaps = False
04 for p = 0 to [Link]-2
05 if queuesize[p] > queuesize[p+1] then
06 temp = queuesize[p]
07 queuesize[p] = queuesize[p+1]
08 queuesize[p+1] = temp
09 swaps = True
10 endif
11 next p
12 endwhile
i. Explain the purpose of the Boolean variable swaps in this bubble sort algorithm.
[2]
ii. Explain the purpose of lines 06 to 08 in this bubble sort algorithm.
[2]
iii. Describe one way that the maintainability of this algorithm could be improved.
[2]
iv. Give the names of two other sorting algorithms that could be used instead of
bubble sort.
[2]
9. Elliott plays football for OCR FC. He wants to create a program to store the results of
each football match they play and the names of the goal scorers. Elliott wants individual
players from the team to be able to submit this information.
Describe two examples of defensive design that should be considered when developing
this program.
[4]
10(a). Louise writes a program to work out if a number entered by the user is
odd or even. Her first attempt at this program is shown.
01 num = input(“enter a number”)
02 if num MOD 2 >= 0 then
03 print(“even”)
04 else
05 pritn(“odd”)
06 endif
The program contains a syntax error on line 05.
i. State what is meant by a syntax error.
[1]
ii. Give a corrected version of line 05 that fixes the syntax error.
[1]
(b). The program contains a logic error on line 02.
i. State what is meant by a logic error.
[1]
ii. Give a corrected version of line 02 that fixes the logic error.
[1]
11. Functions and procedures are both examples of sub programs.
i. Describe one difference between a function and a procedure.
[2]
ii. Describe two benefits to a programmer of using sub programs.
[4]
12. OCR town are holding an election with three candidates (A, B and C). An
electronic voting booth will be used to allow people to vote.
Write an algorithm that:
• Allows voters to enter either A, B or C.
• Keeps track of how many times each candidate has been voted for.
• As soon as one person has finished voting, allows the next person to vote.
At any point allows the official to type in “END”, which will print out the
•
number of votes for each candidate and the total number of votes overall.
[6]
13. Joseph is an author and programmer, and he needs to estimate how many pages his
new book will have.
Each page has an average of 300 words. Each chapter starts with a chapter title page.
The number of pages is estimated by;
dividing the number of words by 300
ignoring the decimal part of the division
adding the number of chapters to this total.
Joseph uses the algorithm below to estimate the number of pages, but his algorithm
does not give the correct result.
01 INPUT numberOfWords
02 INPUT numberOfChapters
03 CONST wordsPerPage = 300
04 numberOfPages = RoundDown(numberOfWords / wordsPerPage)
05 numberOfPages = numberOfWords + numberOfChapters
06 OUTPUT numberOfPages
Joseph has used a RoundDown function to remove the decimal part of the division, e.g.
RoundDown(6.2) would return 6, RoundDown(7.8) would return 7.
There is an error in line 05 of the algorithm.
Write a corrected line of code to replace line 05.
[1]
14(a). Johnny is writing a program to create usernames. The first process he has
developed is shown in the flowchart in Fig. 1.
For example, using the process in Fig. 1, Tom Ward's user name would be TomWa.
State, using the process in Fig. 1, the username for Rebecca Ellis.
[1]
14 (b). Johnny has updated the process used to create usernames as follows:
If the person is male, then their username is the last 3 letters of their surname and
the first 2 letters of their first name.
If the person is female, then their username is the first 3 letters of their first name
and the first 2 letters of their surname.
• What would be the username for a male called Fred Biscuit using the updated
process?
[1]
• Write an algorithm for Johnny to output a username using the updated process.
[6]
15. The area of a circle is calculated using the formula Π × r 2, where Π is equal to 3.142
and r is the radius.
Finn has written a program to allow a user to enter the radius of a circle as a whole
number, between 1 and 30, and output the area of the circle.
Explain, using examples from the program, two ways Finn can improve the
maintainability of the program.
[6]
16. When customers pay using a card such as the one below, shops use computer
systems to process the payment.
* Explain why it is important for computer systems that process card payments to be
reliable.
The quality of written communication will be assessed in your answer.
[6]
17(a). Charley is writing a program for music students. To make sure that there are no
logic errors in the program, Charley uses a test plan.
The program uses the letters in the following list to represent musical notes.
CDEFGAB
When the user inputs a letter from this list, the program outputs the next three notes in
the list.
If it gets to the end of the list, it starts again from the beginning, so the next note after B
is C.
Complete the test plan below by stating, for each input data, the expected outcome and
a reason for the test.
Inp
ut
Expected outcome Reason for test
Dat
a
.............................................................
..................................... ............
C
....... .............................................................
............
.............................................................
..................................... ............
A
....... .............................................................
............
.............................................................
..................................... ............
H
....... .............................................................
............
[6]
(b). Describe what is meant by a logic error.
[2]
END OF QUESTION PAPER