Algorithms - Pseudo-Code - Flowcharts - Answers
Algorithms - Pseudo-Code - Flowcharts - Answers
Algorithms - Pseudo-Code - Flowcharts - Answers
Algorithms Score: /
GCSE Computer Science Questions & Answers
Q1 The final value of left in the algorithm shown in Figure 4 is 4. A programmer realises [4 marks]
that they can use this value to check whether val has been found or not in the algorithm
shown in Figure 4.
The programmer wants to extend the algorithm and introduce a new variable called
found that is true when the value has been found in the array or false otherwise.
Write the pseudo-code or draw the flowchart that is needed to extend the algorithm so
that when the algorithm finishes, the new variable found is:
This code should follow on from the end of the algorithm in Figure 4.
The algorithm in Figure 5 asks the user to enter a number between 0 and 23 that
represents an hour using the 24 hour clock. The input is stored in a variable called
hour.
For example:
• If the user enters 0, the program outputs 12 followed by am.
• If the user enters 4, the program outputs 4 followed by am.
• If the user enters 12, the program outputs 12 followed by pm.
• If the user enters 15, the program outputs 3 followed by pm.
You can assume that the variable hour is an integer and that the value that the user
inputs will be between 0 and 23.
Q3 The kitchen computer system uses a function called newbalance() to calculate a [4 marks]
student’s new account balance when they pay for a meal.
For example, if a student with an account balance of 9.50 has a meal costing 2.20 the
newbalance()function should return the new balance of 7.30.
Q4 OCR Airlines keeps track of customers’ luggage using a printed tracking code on each [4 marks]
item of luggage. Each tracking code is made up of 8 characters and begins with the
letter P or Q.
Q6 OCRApp uses an incremental backup strategy at the end of each working day. [4 marks]
Complete the flowchart by writing the number of the missing statements in the correct
flowchart symbols.
Number Statement
1 Stop
Q7 Using pseudocode, create an algorithm that will write the date of the last backup to a [4 marks]
text file called ‘dates.txt’
Q8 A single record from this database table is read into a program that uses an array with [4 marks]
the identifier studentdata. An example of this array is shown below:
Q9 A library gives each book a code made from the first three letters of the book title in [3 marks]
upper case, followed by the last two digits of the year the book was published.
For example, “Poetry from the War”, published in 2012 would be given the code
POE12.
Complete the following pseudocode for a function definition that will take in the book
title and year as parameters and return the book code.
Q10 Use pseudocode to write an algorithm that does the following : [6 marks]
Q11 Using pseudocode, write an algorithm that will use a count-controlled loop to print out [3 marks]
the numbers 1 to 10 in ascending order
Q12 OCR town are holding an election with three candidates (A, B and C). An electronic [6 marks]
voting booth will be used to allow people to vote.
Q13 A program needs to calculate the size of files in bytes. The program must: [6 marks]
Q14 Develop an algorithm using pseudocode or a flowchart that calculates an estimate of [9 marks]
the braking distance in metres for a new model of go-kart that is travelling between 10
and 50 kilometres per hour (kph).
- the user should keep being asked to enter a speed for the go-kart until they
enter a speed that is between 10 and 50 (both 10 and 50 are valid speeds)
- the braking distance in metres is calculated by dividing the speed by 5
- the user should be asked if the ground is wet (expect the user to enter ‘yes’ if it
is)
- the braking distance should be multiplied by 1.5 when the ground is wet
- finally, your algorithm should output the calculated braking distance.
Q15 Develop an algorithm using pseudocode or a flowchart that asks the user to create a [5 marks]
new password.
The algorithm should:
• get the user to enter a password
• get the user to re-enter the password
• repeat the two bullet points above until both entered passwords are identical
• output "password created" when they are identical.
Q16 State two possible weaknesses of the passwords that this algorithm would accept [2 marks]
Using either pseudocode or a flowchart, extend the algorithm in Figure 5 so that the
variable draw is set to the value true when both player 1 and player 2 choose the same
option. This code should follow on from the end of the algorithm in Figure 5.
Q18 Using either pseudocode or a flowchart, extend the algorithm in Figure 5 and your [9 marks]
answer to question 10(d) by outputting:
• either that the game was a draw
• or, if it was not a draw, which option beat which option.
Example 1: If player 1 entered a 2 and player 2 entered a 3 then the algorithm should
output:
rock
beats
scissors
Example 2: If player 1 entered a 1 and player 2 entered a 2 then the algorithm should
output:
rock
beats
Paper
Your answer should extend the algorithm in Figure 5 and leave the original algorithm
unchanged.
Note: assume that array indexing starts at 1 so OUTPUT options[1] will output the value
paper.
Q20 [1 marks]
AQA Workbook /1
Q21 At Tom’s Tombola, every ticket number ending in either a 5 or a 0 is a winning ticket. [4 marks]
AQA Workbook /4
Answers
Mark as follows:
1 mark for using selection;
1 mark for setting found is assigned the value true and the value false in two separate places
(A. if selection logic is incorrect);
1 mark for using the correct Boolean condition (A. if right has been used instead of left);
1 mark for overall correctness of the solution;
Q2 Mark as follows:
1 mark if it outputs 12am if the input is 0;
1 mark if it outputs 12pm if the input is 12;
1 mark for selecting just the inputs 1 to 11;
1 mark if it outputs 1am to 11am correctly given the corresponding inputs 1 to 11;
1 mark for selecting just the inputs 13 to 23;
1 mark for adjusting the value of hour to be 12 less (using subtraction, modulus or similar);
1 mark if it outputs 1pm to 11pm correctly given the corresponding inputs 13 to 23;
Example algorithm
Example algorithm
Example algorithm
Example algorithm
Q14 Marks awarded for the following. Maximum of 8 marks awarded if the answer includes any
errors.
Example 1
Example 2
Example 3
Q15 Marks awarded as follows (allow any logically equivalent and correct answer). The marks are
labelled A – E and shown in the examples where they are awarded:
A. 1 mark for assigning user input to a variable (permit any variable name);
B. 1 mark for assigning the second user input to a distinct variable from that used in A, or
the second user input used in such a way that doesn’t require a variable, e.g. USERINPUT =
password1; C. 1 mark for using a condition-controlled loop such as a WHILE loop with a
correct Boolean expression to control this loop (this will depend on the type of loop used but
will test for equality of the two passwords);
D. 1 mark for the user inputting the two passwords again within the loop and assigning these
to their respective variables;
E. 1 mark for outputting “password created” at a point in the code where no further user
input will occur (A. spelling mistakes for “password created”);
Q16 Any creditworthy point to a maximum of two. Examples include: They do not have a
minimum length//they can be blank; They do not have to have a mixture of alphabetic and
numeric characters; They may have consecutive numbers within them; They may be easily
guessable names;
Q17
Q18 Marks awarded as follows (allow any logically equivalent and correct answer). The marks are
labelled A – I and shown in the examples where they are awarded:
A. 1 mark for using selection that ‘divides’ the code for a draw from the code for when it is not a
draw. This would probably be either two IF statements or an IF-ELSE;
B. 1 mark for the correct Boolean condition(s) with the selection statements in mark A;
D. 1 mark if the output from mark C is within the correct part of the selection statement;
E. 1 mark for using selection with the correct condition(s) to ascertain which player won (I. if this and
subsequent lines of code are not within the correct part of the selection from mark A);
F. 1 mark for ensuring the winning player’s choice will output first (even if the output is incorrect);
G. 1 mark for outputting the player’s choice (even if this is not the winning player);
I. 1 mark for outputting the choice of the other player from that used in mark F;
B. 1 mark for creating a variable that stores the total number of seconds (permit any variable
name,
seconds has been used in the examples) and instantiating this to zero (mark can only be
awarded if this
iis declared outside of the loop);
C. 1 mark for using a loop to iterate over every page (two logically equivalent examples are given
below
although there are many logically equivalent ways to accomplish this);
D. 1 mark for asking for the user input for the page difficulty; (Note that no marks are awarded for
validating
the user input)
E. 1 mark for using selection to decide if user input is ‘easy’ (this does not need to be explicit and
could
possibly the ELSE clause where the IF is asking if it is ‘difficult’);
F. 1 mark for using selection within the loop; G. 1 mark for increasing the number of seconds by 40
within
the correct selection block;
H. 1 mark for increasing the number of seconds by 100 within the correct selection block;
I. 1 mark for outputting the total number of seconds taken outside of the loop; Example 1 (every
italicised
square bracket indicates where that mark is awarded):
Example 4 using a flowchart (large annotated letters indicate where that mark is awarded):
Q20 Any one problem: 1 mark