Font size
WorksheetsAP1 Paper 2 Computer Science
Total questions: 16
Worksheet time: 39mins
Identify whether the OCR Reference Language code given is an example of selection or iteration.
for i = 1 to 10
print(i)
next i
whilescore != 0
playgame()
endwhile
if playerHit() then
score = 0
endif
switch bonus:
case 0:
score = 9
case 1:
score = 7
case 2:
score = 5
endswit
Write pseudocode to increment a value held in a variable score by one.
(a)
Breaking a complex problem down into smaller problems.
(a)
Hiding or removing irrelevant details from a problem to reduce the complexity.
(a)
A restaurant needs an algorithm designing to help employees work out if a customer can have a half price meal or not. It should:
•input required data
•decide if the customer is entitled to a discount
•output the result of the calculation.
Design the algorithm using a flowchart.
INPUT discCard
If day NOT "saturday"
Output "half price"
Output "Full price"
End
Each member of staff that works in a restaurant is given a Staff ID. This is calculated using the following algorithm.
Identify the three different variables used.
=
str
input
str(year)
endwhile
surname
year
staffID
while
Each member of staff that works in a restaurant is given a Staff ID. This is calculated using the following algorithm.
Identify the first three different operators used
<
+
=
str
input
str(year)
endwhile
surname
year
while
Casting has been used in this code. Casting means changing data from one data type to another. On what line number has Casting been used?
(a)
Concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" + "ball" is "snowball". The concatenation of "Thompson " + "is" + "Jedi" is "ThompsonisJedi".
The concatenation of "Thompson " + "is " + " Jedi". Note the spaces results in "Thompson is Jedi".
Concatenation has been used on three lines. Identify in the code where has Concatenation been used?
01 surname = input(“Enter surname”)
02 year = input(“Enter starting year”)
03 staffID = surname + str(year)
04 while staffID.length < 10
05 staffID = staffID + “x”
06 endwhile
07 print(“ID ” + staffID
Complete the trace table for the given algorithm when the surname “Kofi” and the year 2021 are entered.
Kofe
2022
KofiID
ID Kofi
ID Kofi2021xx
Kofi2021xx
Kofi
2021
Kofi2021
Kofi2021x
Jack is writing a program to add up some numbers. His first attempt at the program is shown.
Which arithmetic operator has been used ?
(a)
Click on the appropriate data type for the following fields:
String
Click on the appropriate data type for the following fields:
Integer
Click on the appropriate data type for the following fields:
Boolean
Jack is writing a program to add up some numbers. His first attempt at the program is shown.
Match the ways that the maintainability of this program could be improved.
Add comments
//Variable a will store first input
Name variables sensibly
total instead of f. Think purpose
Use iteration
Use a for loop to get the 5 inputs
Jack decides to improve his program. He wants to be able to input how many numbers to add together each time the algorithm runs, and also wants it to calculate and display the average of these numbers.
Write an algorithm to:
•ask the user to input the quantity of numbers they want to enter and read this value as input
•repeatedly take a number as input, until the quantity of numbers the user input has been entered
•calculate and output the total of these numbers
•calculate and output the average of these numbers.
