You are on page 1of 18

O

…day … Month Year – Morning/Afternoon


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

Ahmad’s Question paper


Do not use:
a calculator Version 1.3

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 17 pages.

ADVICE
• Read each question carefully before you start to answer.

© OCR 2019 […/…/…]


OCR is an exempt Charity
DC (…) 000000
Turn over
2

Answer all the questions.

Section A

1 A university uses an algorithm to calculate the percentage scholarship given to a student.


The percentage discount is calculated as follows.

 If a student’s household income is below £40,000 there is a 20% discount


 If a student has parents who are key workers there is a 10% discount
 If a student receives a grade 8 or 9 in computer science, there is an extra 10% discount.
 A student cannot receive a military discount if the household income is above £40,000.

(a) Identify 2 variables you will need to use.

…………………………………………………………………………………………………………….

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

(b) Create a flowchart for this algorithm.


……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

[6]
© OCR 2019
3

2 (a) Complete the truth table in Fig. 1 for the Boolean statement P = NOT(A OR B) AND C.

A B C D E F

0 0

0 1

1 0

1 1

Fig. 1
[4]
(b) Draw a logic diagram for P = NOT(A AND B).

P = NOT(A AND B) Tick (ü) one box

[4]

© OCR 2019 Turn over


4

3 A game uses the array numbers in order to generate values.

A sample of this array is shown in Fig. 3.

3 26 92 48 7 19 5

Fig. 3

(a) Show the stages of a merge sort when applied to data shown in Fig. 3.

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

[4]

(b) Explain why the data set above cannot be sorted with a binary sort.

………………………………………………………………………………………………………………

…………………………………………………………………………………………………………..…..

………………………………………………………………………………………………………………

…………………………………………………………………………………………………………..…..

[2]

© OCR 2019
5

7 46 17 54 3 31 2

(c) Show how a linear search would search for the number 54 in the list above.

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

(d) Create an algorithm that returns the value of an index requested in the array from user input.

e.g. numbers[2] 2 returns 46

You must use either:


 OCR Exam Reference Language, or
 a high-level programming language that you have studied.

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

[5]

© OCR 2019 Turn over


6

4 The database table rank stores the rank for each student.

StudentName Coding level Conduct


Ahmad 10 Nuisance
Lionel 6 Good
Luca 8 Good
Silviu 4 Respectful
Miles -5 Exquisite

Complete the SQL query to return all the fields for students with a coding level above 5 with good conduct.

SELECT ……………………………………………………………….…………….…….…….…………

FROM ……………………………………………………………….…………….…….…….…………

WHERE ……………………………………………………………….…………….…….…….…………

[4]

© OCR 2019
7

5 The following program uses a works out whether a number is in the 2 times tables or not.
(a) Fill in the blanks.

x = ……………………………………………………………………

if x ………(2) == 0

print (“The number is in the 2 times tables”)


endif
if x ……(3) == 0

print (“The number is in the 3 times tables”)


else:
…………………………………………………………………………………………….

[4]

(b) State the purpose of the following operators.

Operator Purpose

DIV

[3]

© OCR 2019 Turn over


8

6 The following algorithm generates an email adress


.

firstname = input('Enter your firstname')


lastname = input('Enter your last')
year= number(input("Enter the current year"))
generated_email = year+lastname+firstname[0]
print(generated_email)

(a) There is a mistake in line 3, rewrite the third line correctly.

……………………………………………………………..…………………………………………………..
[1]

(b) Suggest 1 way to improve the maintainability of the code above.

……………………………………………………………..…………………………………………………..
[1]
(c) Complete the following trace table for the given algorithm where the first name “Simely”,
surname “Thomas” and year “2007” are entered.

Line number Firstname Lastname Year Generate_email output


01

02

03

04

05

[4]

© OCR 2019
9

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.

7 A cash app stores the balance of it’s customers.


(a)
Tick () one box to identify the data type you would choose to store the data and explain why
this is a suitable data type.

Data Type Tick () one box

String

Integer

Real

Boolean

Explanation: ……………………………………………………………………………………………….

…………………………………….………………………………………………….……………………..

[2]

© OCR 2019 Turn over


10
(b)
The program should only allow values equal to or above 18 years to register at the bank. If the data
entered breaks this validation rule, an error message is displayed.

(i) Complete the following program to output "Invalid input" if the data does not meet the
validation rule.

You must use either:


 OCR Exam Reference Language, or
 a high-level programming language that you have studied.

age = input("Enter age: ")

if age !=18 …………………… age..............then

…………………………… ("Invalid age") endif

[3]

(ii) Complete the following test plan for the program in 8(b)(i).

Test data Test type Expected result

Normal Value accepted

Invalid input
Invalid
message displayed
Value accepted
18

[2]

© OCR 2019
11
(c)
Data for one week of pay (Monday to Friday) is stored in a 2D array with the identifier salary.

The following table shows part of this array, containing 4 students.

Students

Madison Elias James Fin


0 1 2 3
Days Mon 0 0 68 159 0
of the
week Tue 1 100 243 0 610
Wed 2 15 400 0 200
Thu 3 75 105 62 152
Fri 4 0 123 43 42

The banker wants to output the daily pay for Fin (column index 3) on Tuesday (row index 1). The
following code is written:

print(salary[3,2])

Write a line of code to output the pay that Madison received on Thursday

You must use either:


 OCR Exam Reference Language, or
 a high-level programming language that you have studied.

…………………………………………………………………………………………………………

……………………………………………………………………………………………………… [1]

© OCR 2019 Turn over


12

(d)
The banker wants to work out the amount Madison earnt last week

total = 0

total = total + salary[0,0]

total = total + salary[0,1]

total = total + salary[0,2]

total = total + salary[0,3]

total = total + salary[0,4]

print(total)

Refine the program to be more efficient. Write the refined version of the algorithm. You

must use either:


OCR Exam Reference Language, or
a high-level programming language that you have studied.

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………..

[4]

© OCR 2019
13
(e)
The following program uses a condition-controlled loop.

fruits = ["apple", “orange”, ”cherry”, "banana", "cherry"]


for x in fruits:
  if x == "banana":
    continue
  print(x)

Complete the trace table to test this program.

x x=="banana" output

[4]

© OCR 2019 Turn over


14

(f)
A teacher writes an algorithm to store the name of the game a student plays each night (for example
"OCR weather-teller").
weather = input("Is it hot, cold or wet")
if weather =="hot":
print("wear a t-shirt")
elif weather =="cold":
print("wear a jacket")
elif weather =="wet":
print("wear a raincoat")
else:
print("Suck your mum")

The algorithm needs testing to make sure the IF-ELSE statement works correctly.

Identify two different pieces of test data that can be used to test different outputs of the
algorithm. Give the output from the program for each piece of test data.

Test data 1 ..…………………………………………………………………………………………..

Expected output ..……………………………………………………………………………………..

Test data 2 …………………………………………………………………………………………….

Expected output ..……………………………………………………………………………………..


[4]

© OCR 2019
15

(g)
The teacher asks students how long they spend revising. Students answer in minutes and hours (for
example 2 hours 15 minutes).

The teacher would like to create an algorithm that will display students’ inputs in minutes only.

(i) Identify the input and output required from this algorithm.

Input …….………………………………………………………………………………………………

……...……………………………………………………………………………………………………

Output …..………………………………………………………………………………………………

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

(ii) A program is created to convert hours and minutes into a total number of minutes.

The teacher wants to create a sub program to perform the calculation. The

program has been started but is not complete.

Complete the design for the program.

hours = input("Please enter number of hours revising")

minutes = input("Please enter number of minutes ")

Total = ………………………………………………………………..

print(Total)

function ………………………………………………………………..

………………………………………………………………..

………………………………………………………………..

………………………………………………………………..

………………………………………………………………..

endfunction

[4]

© OCR 2019 Turn over


16

(iii)

Rewrite the flowchart as a program.

You must use either:


 OCR Exam Reference Language, or
 a high-level programming language that you have studied.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

[6]

END OF QUESTION PAPER

© OCR 2019
17

ADDITIONAL ANSWER SPACE

If additional space is required, you should use the following lined page(s). The question number(s) must
be clearly shown in the margin(s).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Copyright Information:

OCR is committed to seeking permission to reproduce all third-party content that it uses in the assessment materials. OCR has attempted to identify and
contact all copyright holders whose work is used in this paper. To avoid the issue of disclosure of answer-related information to candidates, all copyright
acknowledgements are reproduced in the OCR Copyright Acknowledgements booklet. This is produced for each series of examinations and is freely
available to download from our public website (www.ocr.org.uk) after the live examination series.

If OCR has unwittingly failed to correctly acknowledge or clear any third-party content in this assessment material, OCR will be happy to correct its
mistake at the earliest possible opportunity.

For queries or further information please contact the Copyright Team, The Triangle, Shaftesbury Road, Cambridge, CB2 8EA.

OCR is part of the Cambridge Assessment Group; Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate
(UCLES), which is itself a department of the University of Cambridge

© OCR 2019
18

You might also like