All papers

Computer Science · OCR J277 · Computational thinking, algorithms and programming · June 2022

OCR GCSE Computer Science Computational thinking, algorithms and programming June 2022 question paper J277/02

Practise the past exam questions by topic

OCR J277 · Paper 2

5 questions
Report a problem
What is wrong?

Goes to whoever maintains the question split. No account needed and nothing is published on this page.

Question 1

(a)

Tick (✓) one box in each row to identify whether the OCR Reference Language code given is an example of selection or iteration.

Figure for question 1

[4]

(b)

Write pseudocode to increment the value held in the variable score by one.

[1]

(c)

State the name of each of the following computational thinking techniques.

Breaking a complex problem down into smaller problems.

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

[2]

Question 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:

InputValue
AIs a student
BHas a discount card
CThe current day is Saturday
(a)

The logic system P = (A OR B) AND NOT C is used.

(a)(i)

Complete the following logic diagram for P = (A OR B) AND NOT C by drawing one logic gate in each box.

Figure for question 2

[3]

(a)(ii)

A truth table can be produced for this logic circuit.

Describe the purpose of a truth table.

[2]

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

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.

[2]

(d)
Figure for question 2
(d)(i)

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

[2]

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

Figure for question 2

[4]

Question 3

A program stores the following list of positive and negative numbers. The numbers need sorting into ascending order using a merge sort.

Figure for question 3
(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.

Figure for question 3

[3]

Answer
Mark scheme for question 3(a)
(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.

[4]

Answer
Mark scheme for question 3(b)
(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.

[2]

Answer
Mark scheme for question 3(c)

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

[2]

(b)

Jack’s program uses the addition (+) arithmetic operator. This adds together two numbers.

(b)(i)

State the purpose of each of the arithmetic operators in the table.

Figure for question 4

[2]

(b)(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........ 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........ 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........ errors.

The........ file produced can be run........ 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:

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

[6]

Question 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:

firstNameAmaya
surnameTaylor-Ling
nights3
roomPremium
stayCompleteFalse
(a)(i)

State the most appropriate data type for the following fields:

[2]

(a)(ii)

Give the name of one field that could be stored as a Boolean data type.

[1]

(a)(iii)

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 FROM TblBookings IF Nights < 1

The SQL statement is incorrect.

Rewrite the SQL statement so that it is correct.

[4]

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

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

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]

(b)(ii)

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

Test data (number of nights)Type of testExpected output
2ALLOWED
BoundaryALLOWED
Erroneous / InvalidNOT ALLOWED

[3]

(c)

A Basic room costs £60 each night. A Premium room costs £80 each night.

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

[4]

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

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

Question 5, shown as an image
Index012345678
Data213210041

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.

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

[6]

The paper as printed

Spotted a mistake on this page?Report a problem