0% found this document useful (0 votes)
17 views18 pages

Computing HW HalfTerm

This document is an examination paper for the GCSE (9-1) Computer Science subject, focusing on computational thinking, algorithms, and programming. It contains various sections with questions on topics such as logic systems, algorithms, data types, and search methods. The paper includes instructions for candidates, marking schemes, and spaces for answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views18 pages

Computing HW HalfTerm

This document is an examination paper for the GCSE (9-1) Computer Science subject, focusing on computational thinking, algorithms, and programming. It contains various sections with questions on topics such as logic systems, algorithms, data types, and search methods. The paper includes instructions for candidates, marking schemes, and spaces for answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Oxford Cambridge and RSA

Friday 27 May 2022 – Afternoon


GCSE (9–1) Computer Science
J277/02 Computational thinking, algorithms and programming
Time allowed: 1 hour 30
minutes
*9138649804*

Do not use:
• a calculator

*J27702*

Please write clearly in black


Doink.
not write in the barcodes.

Centre number Candidate number

First name(s) Anirudh

Last name Gopalakrishnan

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.

© OCR 2022 [601/8355/X]


DC (ST/CT) 319567/4 R
OCR is an exempt Charity
Turn over
Answer all the questions.

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.

Breaking a complex problem down into smaller problems.

Decomposition

Hiding or removing irrelevant details from a problem to reduce the complexity.

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.

The table identifies the three inputs to the computer system:


Input Value
A Is a student
B Has a discount card
C The current day is Saturday

© 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]

(ii) A truth table can be produced for this logic circuit.

Describe the purpose of a truth table.

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:

• input required data


• decide if the customer is entitled to a discount • output the result of the
calculation.

© OCR 2022 Turn over


4
Design the algorithm using a flowchart.

[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

- Choice between percentage and value [2]

d) Each member of staff that works in the restaurant is given a Staff ID. This is calculated using
the following algorithm.

1 surname = input("Enter surname")


2 year = input("Enter starting year")
3 staffID = surname + str(year)
4 while staffID.length < 10
5 staffID = staffID + "x"
6 endwhile
7 print("ID " + staffID)

(i) Define the term casting and give the line number where casting has been used in
the algorithm.

Definition: Convert one data type to another

Line number: Line 03


[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

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.

45 12 –99 100 –13 0 17 –27

© OCR 2022 Turn over


6
a) The first step is to divide the list into individual lists of one number each. This has been done for
you.
Complete the merge sort of the data by showing each step of the process.

45 12 –99 100 –13 0 17 –27

12 45 -99 100 -13 0 -27 17

-99 12 45 100 -27 -13 0 17

-99 -27 -13 0 12 17 45 100

[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.

- Select the middle number


- Check if the selected number is equal to the target number
- If the searched number is larger, move it left half
- Repeat until the number is found
[4]

(c) A linear search could be used instead of a binary search.

Describe the steps a linear search would follow when searching for a number that is
not in the given list.

- Starting with the first value


- Checking all values in order
[2]

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.

continues crashes debugging error executable

high-level interpreter language low-level many

no one stops with without

Jack writes his program in a high level language. This needs to be

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

produced can be run without the

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.

Write an algorithm to:

© OCR 2022 Turn over


8
• ask the user to input the quantity of numbers they want to enter and read this value as input
• repeatedly take a number as input, until the quantity of numbers the user input has been entered
• calculate and output the total of these numbers
• calculate and output the average of these numbers.

Num = input(“Enter how many numbers”)

For x =1 to num

temp = input("Enter a number”)

total = total + temp

next x

print (total)

print( total / num )

We advise you to spend at least 40 minutes on this section.

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.

(a) A typical booking record is shown in the table:


firstName Amaya
surname Taylor-Ling
nights 3
room Premium
stayComplete False

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]

(ii) Booking records are stored in a database table called TblBookings.

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

The SQL statement is incorrect.

Rewrite the SQL statement so that it is correct.

SELECT FirstName, Surname, Nights, Room, Stay Complete FROM TblBookings

WHERE Nights > 1

[4]

© OCR 2022 Turn over


10
(b) 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 Exam Reference Language, or
• a high-level programming language that you have studied.

valid = True

if firstname == "" or surname == "" then

valid = False

end if

if room != "basic" and room != "premium" then

valid = False

endif

if nights < 1 or nights > 5 then

valid = False

endif if valid then

print("ALLOWED")

else

print ("NOT ALLOWED")

endif

[5]

(ii) Complete the following test plan to check whether the number of nights is
validated correctly.

Test data (number


Type of test Expected output
of nights)

2 Normal ALLOWED

© OCR 2022
11
1 Boundary ALLOWED

7 Erroneous / Invalid NOT ALLOWED


[3]

(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.

You do not have to validate these parameters.

You must use either:


• OCR Exam Reference Language, or
• a high-level programming language that you have studied.

function newPrice(nights, room)

if room == "basic" then

price = 60 * nights

elseif room == "premium" then

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.

You must use either:


• OCR Exam Reference Language, or
• a high-level programming language that you have studied.

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.

The index of room represents the room number.

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)

When tested, the program is found to contain two logic errors.

Describe how the program can be refined to remove these logic errors.

- For loop changed to include 0


- Total = 0 moved to before loop starts [2]
(e) The hotel car park charges £4 per hour. If the car is electric, this price is halved to £2 per
hour.

Write an algorithm to:

• 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.

You must use either:


• OCR Exam Reference Language, or
• a high level programming language that you have studied.

while hours != 0

hours = input("Enter hours")

electric = input("enter Y for electric or N")

if electric == "Y" then

price = hours * 2

elseif electric == "N" then

price = hours * 4

endif

print(price)

endwhile [6]

END OF QUESTION PAPER

© 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
..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

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.

© OCR 2022

You might also like