Programming – O Level Computer Science (2210)
174 questions · page 5 of 12 · Clear filters
Question text
11
A one-player game uses the two-dimensional (2D) array Grid[] to store the location of a secret
cell to be found by the player in 10 moves. Each row and column has 5 cells.
Start
Grid[1,1]
At the start of the game:
•
The program places an ‘X’ in a random cell (not in Grid[1,1]) and empties all the other
cells in the grid.
•
The player starts at the top left of the grid.
•
The player has 10 moves.
During the game:
•
The player can move left, right, up or down by one cell and the move must be within the grid.
•
“You Win” is displayed if the player moves to the cell with ‘X’ and has played 10 moves or
less.
•
“You Lose” is displayed if the player has made 10 moves without finding the ‘X’.
Write a program that meets these requirements.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
Tick (✓) one box to complete the sentence.
Verification is used to make sure that a value entered
A
has not changed during input.
B
is an integer.
C
is correct.
D
is not a string.
[1]
Question text
3
Four pseudocode statements and five pseudocode uses are shown.
(a) Draw one line to link each pseudocode statement to the most appropriate pseudocode use.
Not all pseudocode uses will be required.
Pseudocode use
Pseudocode statement
CALL Colour(NewColour)
counting
finding an average
Value
(A1 + A2 + A3) / 3
totalling
Loop1
Loop1 + 1
using a conditional statement
IF Count > 7 THEN X1
0
using a procedure
[4]
(b) A one‑dimensional (1D) array called Temperatures[] has 25 elements beginning at
index 1. It holds values that range between –20 and 100 inclusive.
Write a pseudocode algorithm using a single loop to find the lowest value in this array and
output the result only once.
You do not need to declare or populate this array.
…
…
…
…
…
…
…
…
…
…
…
… [4]
Question text
4
An algorithm has been written in pseudocode to allow the names of 50 cities and their countries to
be entered and stored in a two‑dimensional (2D) array. The contents of the array are then output.
01
DECLARE City ARRAY[1:50, 1:2] OF BOOLEAN
02
DECLARE Count : INTEGER
03
DECLARE Out : INTEGER
1
04
Count
05
IF
06
OUTPUT "Enter the name of the city"
07
INPUT City[Count, 2]
08
OUTPUT "Enter the name of the country"
09
INPUT City[Count, 2]
Count + 1
10
Count
11
UNTIL Count = 50
1 TO 1
12
FOR Out
13
OUTPUT "The city ", City[Out, 1], " is in ", City[Out, 2]
14
NEXT Out
(a) Identify the four errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe the changes you should make to the corrected algorithm to allow the name of a
country to be input and to display only the stored cities from that country.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
…
…
…
Question text
5
Explain how variables and constants should be used when creating and running a program.
…
…
…
…
…
… [3]
Question text
7
The string operation SUBSTRING(Quote, Start, Number) returns a string from Quote
beginning at position Start that is Number characters long. The first character in Quote is in
position 1.
Write pseudocode statements to:
•
store the string "Learning Never Exhausts The Mind" in Quote
•
extract and display the words "The Mind" from the string
•
output the original string in lower case.
…
…
…
…
…
…
…
…
…
…
…
… [5]
Question text
8
Explain why a programmer would use procedures and parameters when writing a program.
…
…
…
…
…
…
…
… [4]
Question text
10 A database table called Horses stores details about the horses kept at a horse sanctuary.
Code
Breed
BreedOrigin
Gender
Age
Arrived
H002
Arabian
Saudi Arabia
M
5
28/09/2022
H004
Percheron
France
M
5
30/10/2022
H010
Friesian
Netherlands
M
6
15/11/2022
H011
Fjord
Norway
F
4
17/11/2022
H012
Clydesdale
Scotland
M
10
18/11/2022
H015
Arabian
Saudi Arabia
F
5
15/12/2022
H016
Arabian
Saudi Arabia
F
5
15/12/2022
H017
Clydesdale
Scotland
F
4
16/01/2023
H019
Percheron
France
M
3
16/01/2023
H025
Percheron
France
M
7
16/01/2023
H026
Clydesdale
Scotland
F
9
20/01/2023
H030
Clydesdale
Scotland
M
12
20/01/2023
H032
Fjord
Norway
M
3
24/03/2023
H033
Arabian
Saudi Arabia
F
15
27/04/2023
H034
Clydesdale
Scotland
F
4
14/06/2023
H035
Fjord
Norway
M
7
15/06/2023
H036
Friesian
Netherlands
F
15
20/07/2023
H037
Friesian
Netherlands
M
12
20/07/2023
(a) State the number of records in this database table.
… [1]
(b) Give the name of the field that is most suitable to be the primary key.
State the reason for this choice.
Field …
Reason …
…
[2]
(c) The database only allows the data types:
•
Boolean
•
character
•
date/time
•
integer
•
real
•
text.
Complete the table to show the most appropriate data type for each field.
Each data type must be different.
Field
Data type
Breed
Gender
Age
Arrived
[2]
(d) Complete the structured query language (SQL) to return the code and breed of all the horses
whose breed originated in Scotland.
… Code, Breed,
FROM …
WHERE … = "Scotland";
[3]
Question text
11
A wood flooring company stores the names of up to 100 customers in a one‑dimensional (1D) array
Customers[]. A two‑dimensional (2D) array Quotations[] stores details of each customer’s
quotation:
•
length of room (one decimal place)
•
width of room (one decimal place)
•
area of wood required (rounded up to next whole number)
•
choice of wood index (whole number)
•
price of wood required in dollars (two decimal places).
The floor measurements (room length and room width) are taken in metres. All floors are rectangles
and room measurements must be between 1.5 and 10.0 inclusive.
The index of any customer’s data is the same in both arrays. For example, a customer named in
index 4 of Customers[] corresponds to the data in index 4 of Quotations[]
The wood choices available are:
Index
Wood type
Price per square metre ($)
1
Laminate
29.99
2
Pine
39.99
3
Oak
54.99
The data are stored in two 1D arrays named WoodType[] and Price[]. The index of the wood
type and price in their arrays share the same index number.
Write a program that meets the following requirements:
•
input a new customer’s name, room length and room width
•
check that each measurement is valid
•
output an error message and require the measurement to be re‑entered until it is valid
•
calculate the area of the room by multiplying together the length of the room and the width of
the room
•
input the choice of wood and find its price per square metre
•
calculate the price of the wood needed
•
store all data in the relevant array
•
output the customer’s quotation to include: the name of the customer, the choice of wood and
the calculated price of the wood required
•
continue to accept the next customer.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
You will need to initialise WoodType[] and Price[]
All inputs and outputs must contain suitable messages.
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
Tick (3) one box to show which library routine returns the remainder of a division.
A
DIV
B
MOD
C
RANDOM
D
ROUND
[1]
Question text
5
An algorithm has been written in pseudocode to check if a new password is in a list of previously
used passwords OldList[]
If the password is not found, the new password will be stored at the end of the list to replace
"XXXX" already stored there.
01
OUTPUT "Enter your new password "
02
INPUT NewPassword
1
03
Posn
FALSE
04
Found
05
REPEAT
06
IF Password = OldList[Posn]
07
THEN
TRUE
08
Found
Posn + 1
09
ELSE Posn
10
ENDIF
11
UNTIL Found AND OldList[Posn] = "XXXX"
12
IF Found
13
THEN
14
OUTPUT "Password has been used before"
15
ELSE
16
INPUT "New password accepted"
NewPassword
17
OldList[Posn]
18
ENDIF
(a) Identify the three errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
[3]
(b) Complete this flowchart for the corrected algorithm:
START
STOP
[6]
Question text
7
A program uses both local variables and global variables.
Describe two differences between local variables and global variables.
Difference 1 …
…
…
…
Difference 2 …
…
…
…
[4]
Question text
10 A weather station takes temperature readings once an hour for a week. These temperatures are
stored in a two-dimensional (2D) array Temperatures[]
Each column contains 24 readings for a single day. The first temperature is recorded at 00:00 and
the final temperature at 23:00. There are seven columns, one for each day of the week, starting
with Monday and ending with Sunday.
The variables MaxDay, MinDay and AvDay are used to store the maximum, minimum, and
average temperatures for a day. The variables MaxWeek, MinWeek and AvWeek are used to store
the maximum, minimum, and average temperatures for the week.
The array has already been set up and the data stored.
Write a program that meets the following requirements:
•
finds the maximum and minimum temperatures for each day
•
calculates the average temperature for each day
•
outputs for each day:
–
name of the day, for example Monday
–
maximum temperature
–
minimum temperature
–
average temperature
•
finds the maximum and minimum temperatures for the week
•
calculates the average temperature for the week
•
outputs:
–
maximum temperature for the week
–
minimum temperature for the week
–
average temperature for the week.
All temperatures output must be rounded to two decimal places.
You must use pseudocode or program code and add comments to explain how your code works.
All inputs and outputs must contain suitable messages.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
You do not need to initialise the data in the array Temperatures[]
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
Tick ( ü ) one box to show the name of the data structure used to store a collection of data of the
2
same data type.
A
Array
B
Constant
C
Function
D
Variable
[1]
Question text
4
Explain the purpose of the library routines DIV and ROUND
DIV …
…
…
…
ROUND …
…
…
…
[4]