0% found this document useful (0 votes)
55 views

Algorithm Questions 10.4.18

The document describes an algorithm to calculate the equivalent age of a dog in human years. It states that if the dog's age is 2 years or less, the human equivalent is 12 times the dog's age. If the dog's age is more than 2 years, the human equivalent is 24 years for the first 2 years, plus 6 years for each additional year of the dog's age. The algorithm takes the dog's age in years as input, calculates the human equivalent age using the described method, and outputs the result.

Uploaded by

John Rod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Algorithm Questions 10.4.18

The document describes an algorithm to calculate the equivalent age of a dog in human years. It states that if the dog's age is 2 years or less, the human equivalent is 12 times the dog's age. If the dog's age is more than 2 years, the human equivalent is 24 years for the first 2 years, plus 6 years for each additional year of the dog's age. The algorithm takes the dog's age in years as input, calculates the human equivalent age using the described method, and outputs the result.

Uploaded by

John Rod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

OCR GCSE Computing (prev.

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.

The program uses the following method:

• The user inputs age of the dog in years


• If the age is 2 or less, the human equivalent is 12 times the age
• If the age is more than 2, the human equivalent is 24 for the first 2 years, plus 6 for every
additional year.

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]

END OF QUESTION PAPER

© 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]

END OF QUESTION PAPER


© OCR 2013
June 2014 12) 16
12* A free drinks machine in an office provides 20 different drinks.

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.

Write an algorithm for the process described above.

The quality of written communication will be assessed in your answer.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
© OCR 2014
17

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..................................................................................................................................................... [6]

END OF QUESTION PAPER

© 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:

- allow the number of places to move to be input

- use iteration

- ensure that all of the players' names are moved to the correct position in the array

© OCR 2015
...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [6]

END OF QUESTION PAPER

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

Fig. 5 shows an extract from the array:

Number: 0 1 2 3 4 ... ... 99 100

Player: A C B A B

Fig. 5

You have been asked to program part of the game.

Write an algorithm for player A’s turn, which;


• takes as an input the number that player A chooses
• if it has not already been chosen, stores an "A" in that array element
• if it has already been chosen, outputs "taken"
• counts and outputs the quantity of numbers left that have not been chosen. [6]

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© OCR 2016
15

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

END OF QUESTION PAPER

© OCR 2016
AQA GCSE Computer Science (prev. course)

June 2014 12)b

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:

 ask the user how many kilometres the journey will be


 only continue if the user enters a value greater than zero
 set the amount of fuel to a number 100 times greater than the number
of kilometres
 not allow the amount of fuel to be less than 1500
 finally, display the amount of fuel needed.
[7 marks]

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

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

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


[9 marks]

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

............................................................................................................................................

...........................................................................................................................................

M/Jun15/4512/2
June 2016 9)d & e

The algorithm in Figure 5 simulates the game of rock–paper–scissors.

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

1 options ← [‘paper’, ‘rock’, ‘scissors’]


2 player1 ← USERINPUT
3 player2 ← USERINPUT
4 player1HasWon ← false
5 draw ← false
6 IF player1 = 1 THEN
7 IF player2 = 2 THEN
8 player1HasWon ← true
9 ENDIF
10 ENDIF
11 IF player1 = 2 THEN
12 IF player2 = 3 THEN
13 player1HasWon ← true
14 ENDIF
15 ENDIF
16 IF player1 = 3 THEN
17 IF player2 = 1 THEN
18 player1HasWon ← true
19 ENDIF
20 ENDIF

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.

Following on from this, then output:

• 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

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-

June 2017 3)c


School pupils are voting to change the colour of their uniform. They enter the
letter B for blue or the letter R for red. A flowchart for counting the votes is
shown. It is incomplete.
The parallelogram symbol is defined as input or output.
Complete this flowchart to show the algorithm used to count a single vote.
(4)

_I_
to.


OCR A Level Computing (prev. course) – F452

January 2009 1)e

A Computing student has written a program which stores and prints recipes. The student has
written the following algorithm to create the serial file:

OPEN OutputFile in Write Mode


WRITE RecipeName to OutputFile
WRITE NumberOfPeople to OutputFile
FOR each ingredient
WRITE NameOfIngredient,“;”,Units,“;”,Quantity to OutputFile
NEXT ingredient
CLOSE OutputFile

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

Write an algorithm for this process.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© OCR 2009 Turn over


January 2010 4)e

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:

The cost of delivery is calculated as follows:

• There is a basic delivery charge of £5 for all orders.


• If the total weight of an order is more than 1 kg, there is an additional charge of
£0.50 for every extra 0.1 kg.
• If the total volume of an order is more than 1000 cm3, there is an additional charge
of £0.50 for every extra 200 cm3.

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

A programmer is producing a computer program which allocates seats to customers in a small


theatre. The theatre has 10 rows, labelled A to J from front to back, and 15 seats in each row,
numbered 1 to 15 from left to right.

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.

Rule 2: The seats must be as close to the front as possible.

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.

IF goals_of_first_team = goals_of_second_team THEN


points_of(first_team) = points_of(first_team) + 1
points_of(second_team) = points_of(second_team) + 1
END IF

Using the same format, write the algorithm for updating the points if there is a winner.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................ [4]

© OCR 2010 Turn over


June 2010 2)f

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 software contains the following function to perform this check.

01 FUNCTION CheckTotalLength() : BOOLEAN


02 TotalLength = 0
03 FOR i = 1 TO NumberOfSongs
04 TotalLength = TotalLength + SongLength(i)
05 NEXT i
06 RETURN (TotalLength > 80)
07 END FUNCTION

The algorithm for the function CheckTotalLength() contains a FOR loop in lines 03 to 05.

Rewrite this FOR loop as a WHILE loop.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................ [5]

© OCR 2010 Turn over


June 2010 3)c

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

The bingo ticket is printed using the following method.

• For every row in the array


• For every column in that row
o If the value is 0 then output a space,
o otherwise output the value

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]

You might also like