All papers

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

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

Practise the past exam questions by topic

OCR J277 Β· Paper 2

6 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)

The table contains four statements about programming languages.

Tick (βœ“) one box in each row to identify whether each statement describes a low-level programming language or a high-level programming language.

Figure for question 1

[4]

(b)

The variables num1 and num2 store integers.

Write pseudocode to add the integers stored in num1 and num2. Store the result in a variable with the identifier total

[1]

(c)

Three incomplete pseudocode algorithms are given with a description of the purpose of each algorithm.

Write the missing arithmetic operator for each algorithm.

(c)(ii)

Working out if a number is odd or even.

number = 53 if number ……………… 2 == 0 then print("Even number") else print("Odd number")

endif

[1]

(c)(iii)

Finding the difference between two measurements.

measurement1 = 300 measurement2 = 100

difference = measurement1 ……………… measurement2

[1]

(d)

Read the following pseudocode algorithm:

01 start = 3 02 do 03 print(start) 04 start = start - 1 05 until start == -1 06 print("Finished")

Complete the following trace table for the given algorithm.

Figure for question 1

[3]

Question 2

This pseudocode algorithm totals all the numbers in the 0-indexed array scores

01 total = 0 02 for scoreCount = 1 to scores.length – 1 03 scores[scoreCount] = total + total 04 next scoreCount 05 print(total)

The function length returns the number of elements in the array.

The algorithm contains several errors.

Two types of errors in a program are syntax and logic errors.

(a)

State what is meant by a syntax error and a logic error.

[2]

(b)

Identify two logic errors in the pseudocode algorithm.

Write the refined line to correct each error.

Error 1 line number........

Error 2 line number........

[4]

Question 3

An insertion sort is one type of sorting algorithm.

A student has written a pseudocode algorithm to perform an insertion sort on a 1D array names

names = ["Kareem", "Sarah", "Zac", "Sundip", "Anika"] for count = 1 to names.length – 1 pos = count while (pos > 0 and names[pos] < names[pos – 1]) temp = names[pos] names[pos] = names[pos – 1] names[pos – 1] = temp pos = pos – 1 endwhile next count

(a)

Describe the purpose of the variable temp in the insertion sort pseudocode algorithm.

[2]

(b)

An insertion sort contains a nested loop; a loop within a loop. In this pseudocode algorithm the outer loop is a count-controlled loop and the inner loop is a condition-controlled loop.

Explain why the inner loop needs to be a condition-controlled loop.

[2]

(c)

A bubble sort is another type of sorting algorithm.

(c)(i)

Describe one difference between an insertion sort and a bubble sort.

[2]

(c)(ii)

Describe two similarities between an insertion sort and a bubble sort.

[2]

Question 4

Figure for question 4
(a)

Draw a logic diagram for the floodlight.

Question 4, shown as an image
Question 4, shown as an image
Question 4, shown as an image

[3]

Answer
Mark scheme for question 4(a)
(b)

Identify the logic gates for truth table 1 and truth table 2.

ABOutput
000
011
101
111
ABOutput
000
010
100
111

[2]

Answer
Mark scheme for question 4(b)

Question 5

Charlie is developing an adding game. The rules of the game are:

β€’ the player is asked 3 addition questions

β€’ each question asks the player to add together two random whole numbers between 1 and 10 inclusive

β€’ if the player gets the correct answer, 1 is added to their score

β€’ at the end of the game their score is displayed.

(a)

Charlie has been told that the game will need to be tested before giving it to the players.

(a)(i)

Explain why programs should be tested before use.

[2]

(a)(ii)

Complete the table by naming and describing one type of test that should be used on Charlie's program before releasing it.

Figure for question 5

[2]

(a)(iii)

Complete the table by identifying and describing two features of an IDE that can be used when testing a program.

Figure for question 5

[4]

(b)

Validating inputs can reduce errors when a program is being run.

Identify two methods of validation and explain how they can be used on this game.

Validation method 1........

Validation method 2........

[6]

(c)

Write an algorithm to play this game. The rules are repeated from the start of the question here:

β€’ the player is asked 3 addition questions

β€’ each question asks the player to add together two random whole numbers between 1 and 10 inclusive

β€’ if the player gets the correct answer, 1 is added to their score

β€’ at the end of the game their score is displayed.

[6]

Question 6

OCR Security Services is a company that installs intruder alarm systems in commercial buildings.

The systems use a computer that is connected to the door sensors and window sensors.

The following data is stored in the system:

Data storedVariable identifierExample data
The user’s nameUserNameAdmin123
A telephone number to call when the alarm is activatedEmergencyPhoneNumber+449999999999
Whether a door sensor is activatedDoorSensorActiveTrue
Whether a window sensor is activatedWindowSensorActiveTrue
A timer that counts, to the nearest second, how long a door sensor has been activatedDoorActiveTime100
A timer that counts, to the nearest second, how long a window sensor has been activatedWindowActiveTime100
Whether the system is armedSystemArmedTrue
Whether the system is in test modeTestModeActiveTrue
(a)

Below is a table showing some variables within the program.

Tick (βœ“) one box in each row to identify the most appropriate data type for each variable.

Figure for question 6

[4]

(b)

The alarm has an algorithm that decides whether to sound the alarm by checking the data that is stored in the following three variables.

β€’ SystemArmed

β€’ DoorSensorActive

β€’ WindowSensorActive

The alarm will only sound when the alarm has been activated and one or both of the door and window sensors are activated. When the system needs to sound the alarm it calls the pre-written procedure SoundAlarm()

Write a program that checks the data in the variables and calls SoundAlarm() when appropriate.

You must use either:

β€’ OCR Exam Reference Language, or

β€’ A high-level programming language that you have studied.

[4]

(c)
Figure for question 6
(c)(i)

Give the line number where there is concatenation.

[1]

(c)(ii)

Give the identifier of a variable used in the program.

[1]

(c)(iii)

Identify the data type of the data returned by the function CheckSensorCode()

[1]

(c)(iv)

Give the line number that contains a function call.

[1]

(c)(v)

Identify two programming constructs that have been used in the program.

[2]

(d)

The alarm system has a log that stores a record each time a sensor is triggered. This is called an event. The record format is given in the table:

FieldnameDescription
DateThe date the event happened
SensorIDThe sensor that was activated
SensorTypeThe type of sensor that was activated – Door, Motion or Window
LengthThe number of seconds the sensor was triggered (to the nearest second)

The log is stored in a database table called events. The current contents of events is shown:

DateSensorIDSensorTypeLength
05/02/2023WS2Window38
05/02/2023MS1Motion2
06/02/2023DS3Door1
06/02/2023MS2Motion3
06/02/2023MS1Motion2
07/02/2023WS1Window24
07/02/2023DS1Door1

Write an SQL statement to display the sensor IDs of the door sensors that have been triggered for more than 20 seconds.

[3]

(e)

A program written in a high-level language is used to access the data from the database. This program has a procedure, SaveLogs(), that stores the data to an external text file.

The procedure SaveLogs():

β€’ takes the string of data to be stored to the text file as a parameter

β€’ takes the filename of the text file as a parameter

β€’ stores the string of data to the text file.

Write the procedure SaveLogs()

You must use either:

β€’ OCR Exam Reference Language, or

β€’ A high-level programming language that you have studied.

[6]

(f)

OCR Security Services need to identify the total number of seconds the sensors have been activated on a specific date.

The data from the database table events is imported into the program written in a high-level programming language.

The program stores the data in a two-dimensional (2D) string array with the identifier arrayEvents

The data to be stored is shown in the table.

DateSensorIDSensorTypeLength
05/02/2023WS2Window38
05/02/2023MS1Motion2
06/02/2023DS3Door1
06/02/2023MS2Motion3
06/02/2023MS1Motion2
07/02/2023WS1Window24
07/02/2023DS1Door1

In this table, the value of events[1, 1] contains "MS1".

(f)(i)

An array can only store data of one data type. Any non-string data must be converted to a string before storing in the array.

Identify the process that converts integer data to string data.

[1]

(f)(ii)

Write a program that:

β€’ asks the user to input a date

β€’ totals the number of seconds sensors have been activated on the date input

β€’ outputs the calculated total in an appropriate message including the date, for example: Sensors were activated for 40 seconds on 05/02/2023

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