Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Half p2 Cs Gcse

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Oxford Cambridge and RSA

Thursday 25 May 2023 – Afternoon


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

Do not use:
* 9 9 3 2 5 3 3 4 3 8 *

• a calculator

* J 2 7 7 0 2 *

Please write clearly in black ink. Do not write in the barcodes.

Centre number Candidate number

First name(s)

Last name

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 2023 [601/8355/X] OCR is an exempt Charity


DC (ST) 326517/4 Turn over
2
SECTION A

1 (a) The table contains four statements about programming languages.

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

Statement Low-level High-level


The same language can be used on
computers that use different hardware
It allows the user to directly manipulate
memory
It allows the user to write English-like
words
It always needs to be translated into
object code or machine code
[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.

(i) Outputting 12 to the power of 2.

print(12 ……………… 2) [1]

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

© OCR 2023
3
(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.

Line number start Output

[3]
© OCR 2023 Turn over
4
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.

Syntax error ..............................................................................................................................

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

Logic error ................................................................................................................................

...................................................................................................................................................
[2]

(b) Identify two logic errors in the pseudocode algorithm.

Write the refined line to correct each error.

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

Corrected line ...........................................................................................................................

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

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

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

Corrected line ...........................................................................................................................

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

...................................................................................................................................................
[4]

© OCR 2023
5
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]

© OCR 2023 Turn over


6
(c) A bubble sort is another type of sorting algorithm.

(i) Describe one difference between an insertion sort and a bubble sort.

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

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

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

...................................................................................................................................... [2]

(ii) Describe two similarities between an insertion sort and a bubble sort.

1 ........................................................................................................................................

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

2 ........................................................................................................................................

...........................................................................................................................................
[2]

© OCR 2023
7
4 A garden floodlight system uses inputs from sensors and switches to decide whether it should be
turned on.
The table shows the inputs into the system and the meaning of each input value:

Letter Input device Input of 1 Input of 0


A Motion sensor Motion is detected Motion is not detected
Light levels indicate it Light levels indicate it
B Light sensor
is daytime is nighttime
The switch is turned The switch is turned
C Light switch
on off

The floodlight (Q) is designed to be on (Q = 1) when the switch is turned on and the motion
sensor detects motion at nighttime.

(a) Draw a logic diagram for the floodlight.

B Q

[3]

© OCR 2023 Turn over


8
(b) Identify the logic gates for truth table 1 and truth table 2.

Truth table 1: A B Output


0 0 0
0 1 1
1 0 1
1 1 1

Logic gate 1: ........................................................

Truth table 2: A B Output


0 0 0
0 1 0
1 0 0
1 1 1

Logic gate 2: ........................................................


[2]

© OCR 2023
9
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.

(i) Explain why programs should be tested before use.

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

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

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

...................................................................................................................................... [2]

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

Test type Description

[2]

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

Feature Description

[4]

© OCR 2023 Turn over


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

Use ...........................................................................................................................................

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

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

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

Validation method 2 ..................................................................................................................

Use ...........................................................................................................................................

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

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

...................................................................................................................................................
[6]

© OCR 2023

You might also like