Algorithms - Pseudo-Code - Flowcharts - Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Pseudo-code / Flowcharts Name:

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:

• true when val is found in arr


• false when val is not found in arr

This code should follow on from the end of the algorithm in Figure 4.

AQA (2016 Spec) - Specimen Question Paper - Paper 1 /4

Q2 Figure 5 shows the start of an algorithm. [7 marks]

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.

Extend the algorithm in Figure 5, using either pseudo-code or a flowchart, so that it


outputs the equivalent time using the 12 hour clock, ie a number between 1 and 12,
followed by either am or pm.

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.

AQA (2016 Spec) - Specimen Question Paper - Paper 1 /7

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.

Write an algorithm for this function which:


• takes the student’s account balance as a parameter
• takes the cost of the meal as a parameter
• returns the new account balance.

OCR (2016 Spec) - Dec 17 Practice Question Paper - Paper 2 /4

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.

Write an algorithm that:

• Allows a tracking code to be entered


• Decides if the tracking code is valid or not.
• Outputs “VALID” if the code follows the above rules and “INVALID” if it does not.

OCR (2016 Spec) - Dec 17 Practice Question Paper - Paper 2 /4

Q5 Write an algorithm that: [6 marks]

- Asks the user to enter the weight of luggage (in kg)


- Displays an error message if the luggage is over 50kg.
- If the luggage is allowed, calculates the price to be paid and outputs this.
- The first 25 kg of luggage is free and the customer should be charged £10 for
every 1 kg over 25 kg

OCR (2016 Spec) - Dec 17 Practice Question Paper - Paper 2 /6

Q6 OCRApp uses an incremental backup strategy at the end of each working day. [4 marks]

The flowchart describes the stages of an incremental backup.


The function getFileDate() returns the date the current file was last accessed.
The function lastBackupDate() returns the date of the last backup.

Complete the flowchart by writing the number of the missing statements in the correct
flowchart symbols.

Number Statement

1 Stop

2 Move to next file

3 Is there another file?

4 Copy file to backupFile

5 Is fileDate > lastBackupDate()?

OCR (2016 Spec) - Dec 17 Practice Question Paper - Paper 1 /4

Q7 Using pseudocode, create an algorithm that will write the date of the last backup to a [4 marks]
text file called ‘dates.txt’

OCR (2016 Spec) - Dec 17 Practice Question Paper - Paper 1 /4

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:

studentdata = [“Kirstie”, “Homework forgotten”, “-2”, “FALSE”]

The array is zero based, so studentdata[0] holds the value “Kirstie”.


Write an algorithm that will identify whether the data in the studentdata array shows that
a letter has been sent home or not for the student. The algorithm should then output
either “sent” (if a letter has been sent) or “not sent” (if a letter has not been sent).

OCR (2016 Spec) - 2018 Question Paper - Paper 2 /4

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.

OCR (2016 Spec) - 2018 Question Paper - Paper 2 /3

Q10 Use pseudocode to write an algorithm that does the following : [6 marks]

• Inputs the title and year of a book from the user.


• Uses the librarycode function above to work out the book code.
• Permanently stores the new book code to the text file bookcodes.txt

OCR (2016 Spec) - 2018 Question Paper - Paper 2 /6

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

OCR (2016 Spec) - 2018 Question Paper - Paper 2 /3

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.

Write an algorithm that:

• Allows voters to enter either A, B or C.


• Keeps track of how many times each candidate has been voted for.
• As soon as one person has finished voting, allows the next person to vote.
• At any point allows the official to type in “END”, which will print out the number of
votes for each candidate and the total number of votes overall.
OCR (2016 Spec) - 2018 Question Paper - Paper 2 /6

Q13 A program needs to calculate the size of files in bytes. The program must: [6 marks]

- Ask the user to input a file size in megabytes


- calculate and output the number of bytes this represents in a user friendly
format (e.g. "There are 5242880 bytes in 5MB").

Write an algorithm using pseudocode to calculate the number of bytes in a given


number of megabytes.

OCR (2016 Spec) - 2018 Question Paper - Paper 1 /6

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).

Your algorithm should be based on the following method:

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

AQA (2013 Spec) - 2017 Question Paper - Paper 2 /9

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.

AQA (2013 Spec) - 2016 Question Paper - Paper 2 /5

Q16 State two possible weaknesses of the passwords that this algorithm would accept [2 marks]

AQA (2013 Spec) - 2016 Question Paper - Paper 2 /2


Q17 [3 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.

AQA (2013 Spec) - 2016 Question Paper - Paper 2 /3

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

Example 3: If both players entered 1 then the algorithm should output:


draw

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.

AQA (2013 Spec) - 2016 Question Paper - Paper 2 /9


Q19 An English teacher wants to estimate how long it should take his students to read a [9 marks]
book. You have been asked to develop an algorithm to calculate this estimate. The
algorithm must do the following:
- ask the teacher how many pages the book has and store this in an appropriately
named variable
- for every page in the book the algorithm should:
- ask the teacher if the page looks 'easy' or 'difficult'
- if a page is 'difficult' then the total number of seconds should increase by 100
- if a page is 'easy' then the total number of seconds should increase by 40
- after the teacher has entered the difficulty level for all the pages, the algorithm should
output the estimated number of seconds that it should take to read the book.

Write pseudocode or draw a flowchart that represents this algorithm.

AQA (2015 Spec) - Specimen Question Paper - Paper 2 /9

Q20 [1 marks]

Give one problem with this flow chart

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]

Complete the flowchart below to show a ticket number as an input whether it is a


winning ticket as an output

AQA Workbook /4
Answers

Q1 4 marks for AO3 (program)

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;

Q3 1 mark per bullet to max 4.


- Function defined called newbalance…
- ...that allows two parameters to be passed in
- Correct balance calculated using these parameters
- Value returned

Q4 1 mark per bullet to max 4.


- Allows tracking code to be input.
- Checks if tracking code begins with P or Q
- Checks if tracking code is 8 characters in length
- Prints ”VALID” if both of the above are true and invalid if either or both are false

Q5 1 mark per bullet to max 6.

- Inputs weight from user


- Checks if weight is bigger than 50…
- …and displays error message if so.
- Calculates price correctly as (weight-25) x 10 or equivalent
- Checks if weight is less than or equal to 50…
- … and prints out the price if so.

Q6 1 mark for 1/2 correct numbers


2 marks for 3 correct numbers
3 marks for 4 correct numbers
4 marks for 5 correct numbers
Q7 1 mark per bullet to max 4
- Open the “dates.txt” text file (in write mode)
- Obtains the last backup date by calling lastBackupDate()
- ...and writes this out to the text file
- Closes text file

Q8 1 mark per bullet, max 4


- Selection(IF) used
- Comparing studentdata[3]…
- …with “TRUE” or “FALSE” // TRUE or FALSE
- Correct outputs (“sent” and “not sent”)

Example algorithm

Q9 1 mark per filled gap, max 3

01 function librarycode(title, year)


02 parta = title.substring(0, 3)
03 partb = year.substring(2, 2)
04 return parta.upper + partb
05 endfunction

Q10 1 mark per bullet, max 6


- Input title and year from user
- Open bookcodes.txt
- Call the librarycode() function…
- … with the two parameters that match input values
- … write out code obtained to the text file
- Close text file

Example algorithm

Q11 1 mark per bullet, max 3.


- FOR loop used
- That outputs the counter variable
- loops 10 time

Example algorithm

Q12 1 mark per bullet, max 6.

- Initialisation of A, B and C as zero.


- Allows input (of anything) from the user
- Incrementing A, B and C depending on input
- Repeats bullet points 2 and 3
- …stopping only when “END” is entered
- Prints out all 3 individual counts and prints calculated total count

Example algorithm

Q13 1 mark per bullet to max 6


- Output asking for file size (in megabytes)
- Taking number of MB as input
- Multiplying by 1024 or 1000
- Multiplying by 1024 or 1000 (may be same line as bullet 3, this must be the final value
with no further changes)
- Outputting the final bytes value…
- …in an appropriate message

output "Please enter the file size in megabytes"


input numberMB
numberKB = numberMB * 1024 (or 1000)
numberBytes = numberKB * 1024 (or 1000)
output "There are " & numberBytes & " bytes in " & numberMB & "MB"

Q14 Marks awarded for the following. Maximum of 8 marks awarded if the answer includes any
errors.

If variables have not been appropriately updated penalise once.

[A] 1 mark for user input of speed and assigning to a variable;


[B] 1 mark for a loop that checks if the input is [not] in range (Boolean condition may be
incorrect);
[C] 1 mark for a Boolean condition that correctly ensures the speed is [not] in
the correct range and allows for potential reassignment of speed at least
once. The type of structure used will indicate whether the condition should be
true or false if the input is within range, e.g. for a WHILE loop it will be speed
< 10 OR speed > 50 or equivalent and for a REPEAT-UNTIL is will be speed ≥
10 AND speed ≤ 50 or equivalent. Use of AND and OR or equivalent logic must
be correct;
[D] 1 mark for user input occurring again if required (structure need not be correct);
[E] 1 mark for dividing the speed by 5 to calculate the braking distance;
[F] 1 mark for user input for wet ground;
[G] 1 mark for checking if this user input is equal to ‘yes’ using selection;
[H] 1 mark for multiplying the braking distance by 1.5 within this structure (possibly incorrect
selection);
[I] 1 mark for outputting the braking distance at the end of the algorithm; Marks C and D (but
not B) can be awarded if the structure used is selection and not iteration.

Examples of answers and how the marks are awarded:

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;

C. 1 mark for outputting 'draw';

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);

H. 1 mark for outputting the string 'beats';

I. 1 mark for outputting the choice of the other player from that used in mark F;

Example 1 (italicised square brackets indicate where marks are awarded):


Example 4 (notes indicate where marks are awarded):
Q19 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 assigning user input to a variable (permit any variable name, pages has been
used in the
examples);

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

No start / begin box


No stop / end box

Decision box with appropriate question: 1 mark


Q21 Output for winning ticket: 1 mark
Output for losing ticket: 1 mark
Using Stop / End: 1 mark
e.g

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy