J277-02 Computational Thinking Paper 2B - Answers
J277-02 Computational Thinking Paper 2B - Answers
Copyright
Copyright
© 2020 PG Online Limited
The contents of this unit are protected by copyright.
This Sample Paper, Sample Paper Mark Scheme and other associated files distributed with it
are supplied to you by PG Online Limited under licence and may be used and copied by you
only in accordance with the terms of the licence agreement between you and PG Online
Limited. Except as expressly permitted by the licence, no part of the materials distributed
with this unit may be used, reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic or otherwise, without the prior written permission of PG
Online Limited.
Licence agreement
This is a legal agreement between you, the teaching institution, and PG Online Limited. PG
Online Limited grants to you a non-exclusive, non-transferable, revocable licence to use this
Sample Paper, Sample Paper Mark Scheme .and other associated files distributed with it in
the course of teaching by your teachers and/or employees.
The materials distributed with this unit may be copied and used by your teachers and/or
employees on a single site only in the course of their teaching. You warrant that you shall
not, and shall procure that each of your teachers and/or employees shall not, share in any
way any of the materials or part of the materials with any third party, including users on
another site or individuals who are teachers and/or employees of a separate institution. You
acknowledge and agree that the materials must remain with you, the teaching institution, and
no part of the materials may be transferred to another institution. You also warrant that you
shall not, and shall procure that each of your teachers and/or employees shall not, procure,
authorise, encourage, facilitate or enable any third party to reproduce these materials in
whole or in part without the prior permission of PG Online Limited.
In consideration of the licence granted to you, you shall indemnify PG Online Limited against
all liabilities, costs, expenses, damages and losses (including but not limited to any direct,
indirect or consequential losses, loss of profit, loss of reputation and all interest, penalties
and legal costs and all other professional costs and expenses) suffered or incurred by PG
Online Limited arising out of or in connection with the exercise by you of your rights granted
under this licence.
2
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
First names(s)
Surname
PAPER 2B
DO NOT USE
• A calculator.
INSTRUCTIONS
• Write in black ink.
• Write your answer to each question in the space provided.
• Answer all the questions.
INFORMATION
• The total mark for this paper is 80.
• The marks for each question are shown in brackets [ ].
• Quality of written communication will be assessed in this paper in questions marked
with an asterisk (*).
• The student version of this paper has 15 pages.
ADVICE
• Read each question carefully before you start to answer.
3
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
Section A
1. A two-player computer game gives players a bank account each. An amount of starting
money is given, followed by a random amount of money.
1 const START_MONEY = 1500
2 playerABank = START_MONEY
3 playerBBank = START_MONEY
4 playerABank = playerABank + random(0,1000)
5 playerBBank = playerBBank + random(0,1000)
6 print(playerABank)
7 print(playerBBank)
8 START_MONEY = START_MONEY * 2
4
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
2. A software company is making a new address book app which will have the following
features:
• Add a name, email address, address and date of birth
• Search for a name
• Show a reminder a week before a birthday
• Send automatic emails such as on a birthday
• Add notes to any name
(a) Draw a structure diagram for this new software. [3]
5
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
Fig. 1
Show the stages of a binary search when an attempt is made to find the name Ada
in the list. [5]
• Compare Ada to Muhammad (1)
• Less than, so split and take left side (1)
• Further comparison (1 or 2 depending on choices made) (1)
• Final comparison with Eva… (1)
• …which fails, therefore Ada is not in the list (1)
e.g.
Compare Ada to Muhammad.
It is less than so binary search left.
Compare to Grayson.
It is less than so binary search left.
Compare to Eva.
It is less than, but there is no more list left, so Ada is not in the list.
(c) State one pre-requisite that the list must have for a binary search to be
carried out. [1]
It must be sorted (1)
It must be in alphabetical order (1)
3. (a) Complete the truth table for Fig. 1 for the Boolean statement
P = (NOT A) OR (NOT B). [2]
A B P
0 0 1
0 1 1
1 0 1
1 1 0
6
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(b) Complete the following logic diagram for P = (NOT A) OR (NOT B). [3]
4. A website has been set up to teach programming. They have chosen to teach a high-
level language.
(a) One of the first topics on the website is arithmetic operators.
Two of the operators mentioned are * and ^. State the meaning of each of these
operators. [2]
* multiplication (1)
^ exponentiation / to the power of (1)
(b) Before students can run their programs, they first need to compile them.
Explain what happens when a program is compiled. [2]
A translator will translate the source code / a compiler will compile the source code
…. (1)
…into the binary instructions / executable file (1)
This can then be executed / run (1)
The binary instructions / executable file is specific to the CPU that the program will be
run on (1)
The compiler reports errors at the end of compilation (1)
7
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(c) The website tells students to install an Integrated Development Environment (IDE)
to develop their programs.
One facility which the IDE offers is an editor which is used to enter and edit each
program.
Other than entering and editing a program, state two other ways that an
editor can help a programmer develop a program. [2]
Syntax highlighting / making different parts of code different colours (1)
Displaying line numbers (1)
Code folding / allowing sections of code to be hidden (1)
Highlight sections of code where there are errors (1)
Code completion (1)
Auto indentation (1)
5. A student sits two papers for an exam. A program is written to calculate the average of
the two results.
1 paperOne = int(input("Paper 1 result: "))
2 paperTwo = int(input("Paper 2 result: "))
3
4 //find average of two papers
5 total = paperOne + paperTwo
6 average = total / 3
7 print(average)
8
9 //say if they improved
10 if paperTwo > paperOne then
11 print("You improved")
12 else
13 print("You didn’t improve")
(a) Lines 1 and 2 contain the instruction int(…) which is used for casting.
Explain the need for casting in these two lines of the program. [2]
The input will always be a string (1)
Which needs to be converted/cast into an integer (1)
… so that it can be used in calculations (later in the program) (1)
(b) State the purpose of // in lines 4 and 9. [1]
It shows that a comment will follow (1)
(c) In line 5, the + symbol means addition.
If paperOne and paperTwo held strings, state what operation the + symbol
would perform. [1]
Concatenation
(d) Identify the logic error in the program. [1]
Line 6 - It divides total by 3 / it should divide total by 2 (to find the average) (1)
8
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(a) The table below shows fields in the database and possible data types.
Tick (✓) one box in each row to choose the correct data type for each field. [3]
9
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(b) The restaurant needs to print the lunch menus for customers. These should only
have items with a price of less than 10.00.
Complete the SQL query to return the menuItem and Price for all items that are
under 10.00. [3]
7. The file named usernames.txt contains a list of usernames that are allowed access to a
computer system. One username is contained on each line.
An administrator has changed all usernames to have the number 1 at the end.
The program will:
• read all the usernames stored in usernames.txt
• put 1 at the end of each username
• save the new usernames to a file named outputfile.txt
(a) The first username in the file is trobinson. Write the new username
that will be stored in outputfile.txt. [1]
trobinson1
(b) Write an algorithm for the program. Remember that it will need to make
use of basic file handling operations. [6]
• Open file usernames.txt and Open file outputfile.txt / create new file
outputfile.txt
• While there are more lines to read from usernames.txt / while not at end of
file
• … read the line of text
• … concatenate 1 to the end of the line / line = line + "1"
• Write the new line of text to outputfile.txt
• Close the usernames.txt, close outputfile.txt
1 mark for each bullet.
e.g.
open the file usernames.txt
open the file outputfile.txt
while not at end of file
read the line of text into a variable named line
line = line + "1"
write the line to outputfile.txt
close usernames.txt
close outputfile.txt
10
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
Section B
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.
(b) Complete the following test plan for the program in 8(a). [3]
11
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(c) A program is created that will convert the number of seconds taken in a race into
minutes and seconds. A sub program will be used for the conversion.
For example, if 102.3 seconds is input, the output will be 1min42.3.
Complete the program. [5]
You must use either:
• OCR Exam Reference Language, or
• A high-level programming language that you have studied.
seconds = float(input("Enter seconds for race"))
outputString = convertToMin(seconds)
print(outputString)
function convertToMin(secs)
theMins = secs DIV 60
theSecs = secs MOD 60
output = str(theMins) + "min" + str(theSecs)
return output
endfunction
0 1 2 3 4
12.5 12.3 10.4 11.25 10.9
(d) The following line of code is run:
racers = oneHundred.length
State the value stored in the variable racers once the line of code has been run. [1]
5 (1)
12
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(e) The following program determines the fastest race time: [5]
fastestTime = oneHundred[0]
if oneHundred[1] < fastestTime then
fastestTime = oneHundred[1]
endif
if oneHundred[2] < fastestTime then
fastestTime = oneHundred[2]
endif
if oneHundred[3] < fastestTime then
fastestTime = oneHundred[3]
endif
if oneHundred[4] < fastestTime then
fastestTime = oneHundred[4]
endif
print(fastestTime)
Refine the program so that it will work with any array length.
You must use either:
• OCR Exam Reference Language, or
• A high-level programming language that you have studied.
• Initialise fastestTime to the first element of the array and print out the
fastestTime (as per the original program)
• Use of a FOR loop or FOR … IN loop
• Use of array.length to determine the arrays length – accept use of racers
variable from 8(d). Accept use of FOR…IN loop which iterates through the
array.
• Correct if statement to determine if the time is faster
• Store the current item in array as the fastestTime if it is lower
e.g.
fastestTime = oneHundred[0]
for i = 0 to oneHundred.length
if oneHundred[i] < fastestTime then
fastestTime = oneHundred[i]
endif
next i
print(fastestTime)
e.g.
fastestTime = oneHundred[0]
for i in range(0, oneHundred.length):
if oneHundred[i] < fastestTime:
fastestTime = oneHundred[i]
print(fastestTime)
13
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
e.g.
fastestTime = oneHundred[0]
for time in oneHundred:
if oneHundred[i] < fastestTime:
fastestTime = oneHundred[i]
print(fastestTime)
x i Output
5 0
10 1
15 2
20 3
25 4
30 30
x i Output Marks
5 0 MP1
10 1 MP2
15 2
20 3 MP3
25 4
30
30 MP4
14
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
(b) The program has been refined with a new algorithm which will produce the same
output.
Complete the new program below by adding one line of code. [1]
You must use either:
• OCR Exam Reference Language, or
• A high-level programming language that you have studied.
x = 5
x = x * 6
print(x)
10. A program has a 2D array named alphabet. This array stores each letter of the
alphabet along with the frequency that the letter occurs in a sentence. A table showing
the array is given below.
0 1
0 A The letter L would be referenced by the code:
1 B alphabet[11,0]
2 C Look at the following program which works out the
3 D frequency of each letter in a sentence.
4 E sentence = "A VERY LARGE HOUSE"
5 F for i = 0 to sentence.length
6 G for j = 0 to alphabet.length
if sentence[i] == alphabet[j,0]
7 H
alphabet[j,1] = alphabet[j,1] + 1
8 I endif
9 J endfor
10 K endfor
11 L
12 M
13 N
14 O
15 P
16 Q
17 R
18 S
19 T
20 U
21 V
22 W
23 X
24 Y
25 Z
15
Sample Question Paper 2A Mark Scheme
OCR GCSE Computer Science (9-1)
16