Computer Science: Paper 2
Computer Science: Paper 2
Computer Science: Paper 2
Time 3 hours
Paper
reference 4CP0/02
Computer Science
PAPER 2: Application of Computational Thinking
Instructions
• Use black ink or ball-point pen.
• Fill in the boxes at the top of this page with your name,
•
centre number and candidate number.
Answer all questions.
• Answer the questions requiring a written answer in the spaces provided
• Only
– there may be more space than you need.
one programming language (Python, C# or Java) must be used throughout
• Carry
the examination.
out practical tasks on the computer system and save new or amended code using
•
the name given in the question with the appropriate file extension.
Do not overwrite the original code and data files provided to you.
• You must not use the internet during the examination.
Information
•
• The
The total mark for this paper is 80.
marks for each question are shown in brackets
•
– use this as a guide as to how much time to spend on each question.
•
This paper covers Python, C# and Java.
Advice
•
•
Read each question carefully before you start to answer it.
•
Save your work regularly.
*P66490A0116*
P66490A
©2021 Pearson Education Ltd.
1/1/1/1
Answer all questions.
Answer the questions requiring a written answer in the spaces provided.
Some questions must be answered with a cross in a box . If you change your mind about an
answer, put a line through the box and then mark your new answer with a cross .
Carry out practical tasks on the computer system and save new or amended code using the
name given with the appropriate file extension.
Use only ONE programming language throughout the examination.
Indicate the programming language that you are using with a cross in a box .
C# Java Python
A modulus
B OR
C >=
D =
(b) Describe one difference between a one-dimensional array and a
two-dimensional array.
(2)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
*P66490A0216*
(d) Raoul has written a program that counts the number of vowels in a sentence.
Open Q01d in the code editor.
Amend the code by adding a suitable comment (you may need to add more than
one comment to a line):
(i) at the end of the line where there is a relational operator
(1)
(ii) at the end of a line where iteration starts
(1)
(iii) at the end of the line where selection starts
(1)
(iv) at the end of a line where a data structure is initialised.
(1)
Save your amended code as Q01dFINISHED with the correct file extension for
the programming language.
3
*P66490A0316* Turn over
2 A book club uses computer applications.
(a) The club wants a program to ensure that logins are valid.
A flowchart for a test version of the program has been designed.
The test version uses:
• a username of bard423
• a password of nX2934?
Here is the flowchart.
Start
Initialise
variables
Yes
Display welcome
message
Stop
4
*P66490A0416*
5
*P66490A0516* Turn over
(b) The club sells books.
It needs a computer program to monitor:
• the number of books sold
• the amount of profit made.
Q02b provides a structure for the program.
Open Q02b in the code editor.
Amend the code to complete the If statement used to produce the outputs
described in the table.
Number of books sold is at least 5 and Sales and profit are good this week
profit made is at least 10
Number of books sold is over 20 and Sales and profit are excellent this week
profit made is at least 20
Number of books sold is under 5 or profit Poor performance this week
made is under 5
6
*P66490A0616*
booksSold
Poor performances this week
profit
booksSold
Sales and profit are good
this week
profit
booksSold
Sales and profit are excellent
this week
profit
7
*P66490A0716* Turn over
3 Several encryption algorithms have been developed.
(a) Ahmed has started to create a Caesar cipher encryption program.
Caesar cipher encryption works by giving a number value to a key.
Each letter in a plaintext message is replaced by a new ciphertext letter using
the key.
For example, as shown in the table, a key value of +2 would change the plaintext
message encrypt to the ciphertext message gpetarv.
Plaintext e n c r y p t
Ciphertext g p e t a r v
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
*P66490A0816*
(c) The Vigenere cipher encrypts plaintext using a series of Caesar ciphers, based on
the letters of a keyword and a Vigenere square.
Figure 1 shows a Vigenere square.
a b c d e f g h i j k l m n o p q r s t u v w x y z
a a b c d e f g h i j k l m n o p q r s t u v w x y z
b b c d e f g h i j k l m n o p q r s t u v w x y z a
c c d e f g h i j k l m n o p q r s t u v w x y z a b
d d e f g h i j k l m n o p q r s t u v w x y z a b c
e e f g h i j k l m n o p q r s t u v w x y z a b c d
f f g h i j k l m n o p q r s t u v w x y z a b c d e
g g h i j k l m n o p q r s t u v w x y z a b c d e f
h h i j k l m n o p q r s t u v w x y z a b c d e f g
i i j k l m n o p q r s t u v w x y z a b c d e f g h
j j k l m n o p q r s t u v w x y z a b c d e f g h i
k k l m n o p q r s t u v w x y z a b c d e f g h i j
l l m n o p q r s t u v w x y z a b c d e f g h i j k
m m n o p q r s t u v w x y z a b c d e f g h i j k l
n n o p q r s t u v w x y z a b c d e f g h i j k l m
o o p q r s t u v w x y z a b c d e f g h i j k l m n
p p q r s t u v w x y z a b c d e f g h i j k l m n o
q q r s t u v w x y z a b c d e f g h i j k l m n o p
r r s t u v w x y z a b c d e f g h i j k l m n o p q
s s t u v w x y z a b c d e f g h i j k l m n o p q r
t t u v w x y z a b c d e f g h i j k l m n o p q r s
u u v w x y z a b c d e f g h i j k l m n o p q r s t
v v w x y z a b c d e f g h i j k l m n o p q r s t u
w w x y z a b c d e f g h i j k l m n o p q r s t u v
x x y z a b c d e f g h i j k l m n o p q r s t u v w
y y z a b c d e f g h i j k l m n o p q r s t u v w x
z z a b c d e f g h i j k l m n o p q r s t u v w x y
Figure 1
Complete the table to perform a Vigenere decryption of the ciphertext message
flmktrwhee using the keyword thirty.
(4)
Encrypted letter f l m k t r w h e e
Keyword letter
Decrypted letter
9
*P66490A0916* Turn over
(d) A user-defined function uses a Vigenere cipher to encrypt plaintext
into ciphertext.
This pseudocode shows how the function is called.
SET ciphertext TO ciphertext & getCipherLetter(keywordLetter, plaintextLetter)
(i) State what would be returned by this function.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
*P66490A01016*
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
*P66490A01116* Turn over
(ii) Figure 2 shows an algorithm for a binary search.
1 # Initialise variables
2 SET productSearch TO " "
3 SET startPosition TO 1
4 SET midPosition TO 0
5 SET endPosition TO LENGTH(productList)
6 SET found TO False
7
8 # Print prompts, take and check input from user
9 SEND "Enter the product code" TO DISPLAY
10 RECEIVE productSearch FROM (STRING) KEYBOARD
11 REPEAT
12 midPosition = (startPosition + endPosition) DIV 2
13 IF productList[midPosition] < productSearch THEN
14 startPosition = midPosition + 1
15 END IF
16 IF productList[midPosition] > productSearch THEN
17 endPosition = midPosition – 1
18 END IF
19 UNTIL productList[midPosition] = productSearch OR startPosition = endPosition
Figure 2
This binary search algorithm will be used to search the product list for the
product code str15.
Complete the table to indicate the order in which the product codes will be
examined by the algorithm.
Write the number 1 by the first product code to be examined, 2 by the second
code to be examined, and so on.
(4)
1 ark11
2 asp11
3 bar13
4 dri15
5 mil19
6 rib10
7 str15
8 tor16
12
*P66490A01216*
(iii) Zak has another list containing the names of five students who attend the
after-school club.
Give the maximum number of names that would need to be examined by the
binary search algorithm to determine whether a name appears in the list.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(iv) Give the name of an algorithm that could be used to sort a list.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
*P66490A01316* Turn over
5 Bianca has started to write a program.
The program is a guessing game about countries and their capital cities.
Open Q05 in the code editor.
The program already:
• displays this menu
Menu
[1] Add player name
[2] Play guess the capital city
[3] End game
14
*P66490A01416*
15
*P66490A01516*
BLANK PAGE
16
*P66490A01616*