Algorithm Questions 10.4.18
Algorithm Questions 10.4.18
course)
June 2011 9)
13
9 A dog that is 5 years old is equivalent to a 42 year old human. Ashok is writing a program which
converts the age of a dog to the equivalent age for a human.
Write an algorithm to calculate and output the human equivalent of the age of a dog using the
method described.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..................................................................................................................................................... [5]
[END]
© OCR 2011
June 2012 12)c
15
(c) A taxi company uses a computer to communicate with central office and to calculate
customers' fares. The cost of a day-time journey is £3 for the first kilometre and £2 for every
kilometre after that. If there are five or more passengers in the taxi, an extra 50% is added to
the charge.
Write an algorithm to calculate the cost of a day-time journey.
Your algorithm should:
• allow the number of passengers and the distance of the journey to be input as whole
numbers,
• calculate the cost of the journey,
• output the cost that has been calculated.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [7]
© OCR 2012
January 2013 12)c 13
(c) Jim is writing a program to calculate the wages of workers in a teddy bear factory. The
wages earned by a worker is either £2 for every teddy bear they have made or £5 for
every hour they have worked, whichever is larger.
Write an algorithm that:
• allows the user to input the number of teddy bears made and the number of hours
worked
• calculates the wages for the number of teddy bears made
• calculates the wages for the number of hours worked
• outputs the larger of the two results.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
© OCR 2013
June 2013 10) 14
10 An isosceles triangle is a triangle that has at least two equal sides. The diagram below shows
examples of isosceles triangles. In each diagram the marked sides are equal.
Write an algorithm for a computer program that determines whether a triangle is an isosceles
triangle.
• The user inputs the lengths of the three sides as Length1, Length2 and Length3
• If any two sides have the same length the program outputs “Isosceles”
• Otherwise the program outputs “Not Isosceles”
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [5]
The machine has a small keypad with keys 0 to 9, OK and CANCEL. It also has a small LCD
screen, which can display a short message.
To get a drink, users select an item number between 1 and 20 with the keypad and confirm their
choice by pressing OK. If they make a mistake they can press the CANCEL button and start again.
If the selection is valid and the drink is available it dispenses the drink. The display screen is used
to show suitable short messages throughout the process.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
© OCR 2014
17
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..................................................................................................................................................... [6]
© OCR 2014
June 2015 10) 18
10 A game on a computer shows six players around a table on seats. They are numbered 1 to 6 as
shown below.
Helen
1
Chan Adam
6 2
5 3
Priya Lidia
4
Kwaku
The names of the players are stored in an array with six elements called PlayerName. The
index position of the array is used to indicate the seat number.
For example, the value of PlayerName(1) is “Helen”.
During the game, each player sometimes moves clockwise by a given number of places.
For example, if the number of places is 2, Helen will move to seat 3, Priya will move to seat 1 etc.
Write an algorithm that will update the contents of the array PlayerName after a move has
occurred. Your algorithm should:
- use iteration
- ensure that all of the players' names are moved to the correct position in the array
© OCR 2015
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [6]
© OCR 2015
June 2016 9) 14
9 A memory game is played where:
• three players (A, B and C) have to choose a number between 0 and 100
• if the number has already been chosen, a message is displayed that says "taken"
• if the number has not already been chosen, the player’s letter is placed next to it
• the quantity of numbers that have not yet been chosen is displayed.
The winner is the player who has chosen the most unique numbers by the end of the game.
The numbers are stored in an array; numbers(). A number that has not yet been chosen is stored
as an empty string "". The players are represented by "A", "B" and "C".
Player: A C B A B
Fig. 5
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
© OCR 2016
15
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
© OCR 2016
AQA GCSE Computer Science (prev. course)
Write an algorithm (using either pseudocode or a flowchart) that calculates the amount of fuel a train
will need to complete a journey. The algorithm must:
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
June 2015 9)
An English teacher wants to estimate how long it should take his students to read a
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
if a page is 'difficult' then the total number of seconds should increase by 100
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.
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
...........................................................................................................................................
M/Jun15/4512/2
June 2016 9)d & e
Player 1 enters the number 1 for paper, the number 2 for rock or the number 3 for
scissors. Player 2 then does the same.
You should assume that the numbers entered by the players are stored as integers.
Note: line numbers have been included but are not part of the algorithm.
Figure 5
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.
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
M/Jun15/4512/2
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.
[12 marks]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
M/Jun15/4512/2
•
•
•
-1-
_I_
to.
•
OCR A Level Computing (prev. course) – F452
A Computing student has written a program which stores and prints recipes. The student has
written the following algorithm to create the serial file:
(‘WRITE’ writes a string into a text file and moves to the next line.)
The program can be used to calculate the quantities necessary to cater for different numbers of
people.
• The user inputs the new number of people.
• The data for the recipe is read one line at a time.
• For each ingredient the new quantity is calculated …
• … the data is output to a new file.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
A mail order company charges for delivery depending on the volume and the weight of the items
purchased. A program processes orders and calculates the cost of delivery. Here is an extract:
Write an algorithm for a function which makes use of the global variables TotalWeight and
TotalVolume and returns the cost of delivery.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [7]
© OCR 2010
June 2009 4)c
The program uses the following rules to choose the best seats.
Rule 1: All seats in one booking must be in the same row, next to each other.
Write an algorithm which takes the number of tickets wanted as an input, and outputs the best seats
available.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© OCR 2009
June 2010 1)b
A program is designed to store the results of matches in a football competition and calculate the
rankings of the teams. When the results are entered, the number of points of each team are updated as
follows:
• If both teams have the same number of goals (draw) then each team gets 1 point.
• If one team has more goals than the other (i.e. there is a winner) then the winning team gets 3
points, and the losing team gets 0 points.
The algorithm for updating points in the case of a draw is given below.
Using the same format, write the algorithm for updating the points if there is a winner.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ [4]
Tacompil Ltd is a company which owns vending machines where customers can purchase audio CDs
containing songs of their choice. The playing length of each song, which has been selected, is stored in
an array called SongLength. When the user wants to write the songs selected onto a CD, the software
must check that the total playing length does not exceed 80 minutes.
The algorithm for the function CheckTotalLength() contains a FOR loop in lines 03 to 05.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ [5]
A printing company uses a computer program to randomly generate and print bingo tickets.
Each bingo ticket has a grid with three rows and nine columns. Each row contains 5 numbers and 4
blank spaces.
4 32 45 68 82
9 26 51 62 88
24 47 55 65 71
Write an algorithm in pseudo-code to print the numbers in the array onto a ticket. You should indent
your pseudo-code correctly to make it easier to understand.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ [8]