J277-02 Computational Thinking Paper 2B
J277-02 Computational Thinking Paper 2B
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 (*).
• This document has 15 pages.
ADVICE
• Read each question carefully before you start to answer.
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
(d) Explain why line 8 will cause an error in the program. [2]
(e) State the maximum value that could be output for playerABank on line 6. [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]
Fig. 1
(b) Show the stages of a binary search when an attempt is made to find the name Ada
in the list. [5]
(c) State one pre-requisite that the list must have for a binary search to be
carried out. [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
0 1 1
1 0 1
1 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]
*
(b) Before students can run their programs, they first need to compile them.
Explain what happens when a program is compiled. [2]
(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]
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]
(f) When paperOne and paperTwo store the same values, state the output
from the program. [1]
(g) The program has been written in such a way as to make it easy to maintain.
Identify two features of the program that make it maintainable. [2]
(h) The table below shows key features of different types of testing that could be used
as part of the program’s development.
Tick () one box in each row to match the feature with the most appropriate
type of test. [2]
(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]
FROM ____________________________________________________________
WHERE ___________________________________________________________
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]
(b) Write an algorithm for the program. Remember that it will need to make
use of basic file handling operations. [6]
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]
3600
3601 Invalid
(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 ______________________________________________________
endfunction
Five runners’ times for the 100 metres race have been stored in an array named
oneHundred which is shown in the following table.
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]
(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.
x i Output
(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
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
1 B
2 C
3 D
4 E
5 F
6 G
7 H
8 I
9 J
10 K
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
The letter L would be referenced by the code:
alphabet[11,0]
Look at the following program which works out the frequency of each letter in a sentence.
sentence = "A VERY LARGE HOUSE"
for i = 0 to sentence.length
for j = 0 to alphabet.length
if sentence[i] == alphabet[j,0]
alphabet[j,1] = alphabet[j,1] + 1
endif
endfor
endfor
(b) Explain the difference between the == operator and the = operator. [2]
(c) Refine the program so that it will output each item from the alphabets array
once the frequencies have been calculated. [3]
The format of the output should be as follows:
A:2
B:0
C:0
D:0
E:3
You must use either:
• OCR Exam Reference Language, or
• A high-level programming language that you have studied.