Computing HW HalfTerm
Computing HW HalfTerm
Do not use:
• a calculator
*J27702*
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 80.
• The marks for each question are shown in brackets [ ].
• This document has 20 pages.
ADVICE
• Read each question carefully before you start your answer.
SECTION A
2
1 (a) Tick (3) one box in each row to identify whether the OCR Reference Language code given is an
example of selection or iteration.
OCR Reference Language code Selection Iteration
for i = 1 to 10
print(i) next i
while score != 0
playgame() endwhile
if playerHit() then
score = 0 endif
switch bonus:
case 0:
score = 9
case 1:
score = 7
case 2:
score = 5
endswitch
[4]
(b) Write pseudocode to increment the value held in the variable score by one.
Score = score + 1
[1]
(c) State the name of each of the following computational thinking techniques.
Decomposition
Abstraction [2]
2 A fast food restaurant offers half-price meals if the customer is a student or has a discount card.
The offer is not valid on Saturdays.
A computer system is used to identify whether the customer can have a half-price meal.
© OCR 2022
3
(a) The logic system P = (A OR B) AND NOT C is used.
(i) Complete the following logic diagram for P = (A OR B) AND NOT C by drawing one logic gate in each
box.
[3]
A show all the possible inputs and the output for each input
(iii) State how many rows (excluding any headings) would be required in a truth table for the logic
expression:
P = (A OR B) AND NOT C
[1]
(b) The restaurant needs an algorithm designing to help employees work out if a customer can
have a half price meal or not. It should:
[5
(c) The restaurant adds a service charge to the cost of a meal depending on the number of ]
people at a table. If there are more than five people 5% is added to the total cost of each
meal.
Customers can also choose to leave a tip, this is optional and the customer can
choose between a percentage of the cost, or a set amount.
Identify all the additional inputs that will be required for this change to the algorithm.
© OCR 2022
5
- Number of people
d) Each member of staff that works in the restaurant is given a Staff ID. This is calculated using
the following algorithm.
(i) Define the term casting and give the line number where casting has been used in
the algorithm.
(ii) Complete the following trace table for the given algorithm when the surname “Kofi”
and the year 2021 are entered.
01 Kofi
02 2021
03 Kofi2021
05 Kofi2021x
05 Kofi2021xx
07 ID Kofi2021xx
[4]
3 A program stores the following list of positive and negative numbers. The numbers need sorting
into ascending order using a merge sort.
[3]
b) Once the numbers are in order, a binary search can be run on the data.
Describe the steps a binary search will follow to look for a number in a sorted list.
Describe the steps a linear search would follow when searching for a number that is
not in the given list.
4 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)
(a) Give two ways that the maintainability of this program could be improved.
- Add comments
- Use iterations
[2]
(b) Jack’s program uses the addition (+) arithmetic operator. This adds together two numbers.
© OCR 2022
7
(i) State the purpose of each of the arithmetic operators in the table.
Arithmetic operator Purpose
Multiplication
Division
[2]
(ii) Complete the description of programming languages and translators by writing the correct
term from the box in each space.
translated into assembly or machine code before it can be executed. This is done using
a translator.
One type of translator is an interpreter. This converts one line of code and then
executes it, before moving to the next line. It stops when an error is found, and when
corrected continues running from the same position. This translator is helpful when
debugging code.
A second type of translator is a compiler. This converts all of the code and produces
an error report. The code will not run until there are no errors. The executable file
compiler.
[5]
(c) Jack decides to improve his program. He wants to be able to input how many numbers to add
together each time the algorithm runs, and also wants it to calculate and display the average of these
numbers.
For x =1 to num
next x
print (total)
Some questions require you to respond using either the OCR Exam Reference Language or a
high-level programming language you have studied. These are clearly shown.
5 Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose between a
basic room or a premium room.
i) State the most appropriate data type for the following fields:
Nights = integer
Room = string
[2]
(i) Give the name of one field that could be stored as a Boolean data type.
stayComplete [1]
The following SQL statement is written to display all customer bookings that
stay more than one night.
SELECT ALL
© OCR 2022
9
FROM TblBookings
IF Nights < 1
[4]
valid = True
valid = False
end if
valid = False
endif
valid = False
print("ALLOWED")
else
endif
[5]
(ii) Complete the following test plan to check whether the number of nights is
validated correctly.
2 Normal ALLOWED
© OCR 2022
11
1 Boundary ALLOWED
(c) A Basic room costs £60 each night. A Premium room costs £80 each night.
(i) Create a function, newPrice(), that takes the number of nights and the type
of room as parameters, calculates and returns the price to pay.
price = 60 * nights
price = 80 * nights
endif
return price
endfunction [4]
(ii) Write program code, that uses newPrice(), to output the price of staying in
a Premium room for 5 nights.
print(newPrice("premium", 5))
x = newPrice(5, "premium")
print(x) [3]
(d) The hotel has nine rooms that are numbered from room 0 to room 8.
The number of people currently staying in each room is stored in an array with the
identifier room.
Array room
© OCR 2022 Turn over
12
Index 0 1 2 3 4 5 6 7 8
Data 2 1 3 2 1 0 0 4 1
The following program counts how many people are currently staying in the hotel.
for count = 1 to 8
total = 0
total = total + room[count]
next count print(total)
Describe how the program can be refined to remove these logic errors.
• take as input the number of hours the user has parked and whether their car is electric or not
• calculate and output the total price
• repeat continually until the user enters 0 hours.
while hours != 0
price = hours * 2
price = hours * 4
endif
print(price)
endwhile [6]
© OCR 2022
13
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).
© OCR 2022
14
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
© OCR 2022
15
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
© OCR 2022
16
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
© OCR 2022
17
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
© OCR 2022