Programming – O Level Computer Science (2210)

174 questions · page 6 of 12 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
76
2210/21/M/J/23 · Question 5May/June 2023Paper 218 marks
Loading question…
Question text

5
An algorithm has been written in pseudocode to allow some numbers to be input. All the positive
numbers that are input are totalled and this total is output at the end.
An input of 0 stops the algorithm.
←
1
01
Exit
02
WHILE Exit <> 0 DO
03
INPUT Number
04
IF Number < 0
05
THEN
←
Total + Number
06
Total
07
ELSE
08
IF Number = 0
09
THEN
←
1
10
Exit
11
ENDIF
12
ENDIF
13
ENDIF
14
OUTPUT "The total value of your numbers is ", Number
(a) Identify the four errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe how you could change the corrected algorithm to record and output how many
positive numbers have been included in the final total.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
… [4]

77
2210/21/M/J/23 · Question 6May/June 2023Paper 214 marks
Loading question…
Question text

6
State two features that should be included to create a maintainable program.
Give a reason why each feature should be used.
1 …
…
…
…
2 …
…
…
…
[4]

78
2210/21/M/J/23 · Question 7May/June 2023Paper 217 marks
Loading question…
Question text

7
The flowchart represents an algorithm.
START
Pointer
1
INPUT
Letter
IS
No
Word[Pointer, 1]
Pointer
Pointer
+ 1
= Letter ?
Yes
OUTPUT "Letter ", Letter,
" is represented by ",
Word[Pointer, 2]
OUTPUT "Another Letter?
(Y or N)"
INPUT Choice
IS
No
Yes
Choice =
STOP
'Y' ?
The table represents the two-dimensional (2D) array Word[] which stores the first half of the
phonetic alphabet used for radio transmission. For example, Word[10,1] is ‘J’.
Index
1
2
1
A
Alpha
2
B
Bravo
3
C
Charlie
4
D
Delta
5
E
Echo
6
F
Foxtrot
7
G
Golf
8
H
Hotel
9
I
India
10
J
Juliet
11
K
Kilo
12
L
Lima
13
M
Mike
(a) Complete the trace table for the algorithm by using the input data: F, Y, D, N
Pointer
Letter
Choice
OUTPUT
[4]
(b) Identify the type of algorithm used.
…
… [1]
(c) Describe one problem that could occur with this algorithm if an invalid character was input.
…
…
…
… [2]

Advertisement
79
2210/21/M/J/23 · Question 8May/June 2023Paper 215 marks
Loading question…
Question text

8
The function LENGTH(Phrase) calculates the length of a string Phrase
(a) Write the pseudocode statements to:
•
store the string "The beginning is the most important part" in Phrase
•
calculate and output the length of the string
•
output the string in upper case.
…
…
…
…
…
… [3]
(b) Write the output your pseudocode should produce.
…
…
…
… [2]

80
2210/21/M/J/23 · Question 10May/June 2023Paper 218 marks
Loading question…
Question text

10 A database table called TVRange shows the main features and prices of a range of televisions.
TVCode
ScreenSize
Satellite
SmartTV
SoundBar
Price$
TV90SaSmSd
90
YES
YES
YES
9750.00
TV75SaSmSd
75
YES
YES
YES
8500.00
TV75SaSd
75
YES
NO
YES
8000.00
TV65SaSmSd
65
YES
YES
YES
6000.00
TV65SmSd
65
NO
YES
YES
5000.00
TV65SaSd
65
YES
NO
YES
5000.00
TV55SaSmSd
55
YES
YES
YES
4000.00
TV55SaSd
55
YES
NO
YES
3500.00
TV55SmSd
55
NO
YES
YES
3500.00
TV50SaSmSd
50
YES
YES
YES
2500.00
TV50Sa
50
YES
NO
NO
1750.00
TV50Sm
50
NO
YES
NO
1750.00
TV40Sa
40
YES
NO
NO
1200.00
TV40
40
NO
NO
NO
950.00
TV32
32
NO
NO
NO
650.00
(a) Give the name of the field that is most suitable to be the primary key.
State the reason for this choice.
Field …
Reason …
…
[2]
(b) The database uses the data types:
•
text
•
character
•
Boolean
•
integer
•
real
•
date/time.
Complete the table to show the most appropriate data type for each field.
Each data type must be different.
Field
Data type
TVCode
ScreenSize
SmartTV
Price$
[2]
(c) Complete the structured query language (SQL) query to return the television (TV) code,
screen size and price of all Smart TVs in the database table.
SELECT TVCode, … , …
… TVRange
WHERE SmartTV = … ;
[4]

81
2210/21/M/J/23 · Question 11May/June 2023Paper 2115 marks
Loading question…
Question text

11
A one-dimensional (1D) array Days[] contains the names of the days of the week. A
two-dimensional (2D) array Readings[] is used to store 24 temperature readings, taken once
an hour, for each of the seven days of the week. A 1D array AverageTemp[] is used to store the
average temperature for each day of the week.
The position of any day’s data is the same in all three arrays. For example, if Wednesday is
in index 4 of Days[], Wednesday’s temperature readings are in index 4 of Readings[] and
Wednesday’s average temperature is in index 4 of AverageTemp[]
The temperature readings are in Celsius to one decimal place. Temperatures can only be from
–20.0 °C to +50.0 °C inclusive.
Write a program that meets the following requirements:
•
input and validate the hourly temperatures for one week
•
calculate and store the average temperature for each day of the week
•
calculate the average temperature for the whole week
•
convert all the average temperatures from Celsius to Fahrenheit by using the formula
Fahrenheit = Celsius * 9 / 5 + 32
•
output the average temperature in Celsius and in Fahrenheit for each day
•
output the overall average temperature in Celsius and in Fahrenheit for the whole week.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays, variables or constants; you may assume that this has
already been done.
All inputs and outputs must contain suitable messages.
All data output must be rounded to one decimal place.
You will need to initialise and populate the array Days[] at the start of the program.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

82
2210/22/M/J/23 · Question 4May/June 2023Paper 227 marks
Loading question…
Question text

4
A program needs to make sure the value input for a measurement meets the following rules:
•
the value is a positive number
•
a value is always input
•
the value is less than 1000.
(a) Describe the validation checks that the programmer would need to use.
…
…
…
…
…
… [3]
(b) The program needs editing to include a double entry check for the value input.
(i)
State why this check needs to be included.
…
… [1]
(ii)
The input value needs to be stored in the variable Measurement
Write pseudocode to perform the double entry check until a successful input is made.
…
…
…
…
…
…
…
… [3]

83
2210/22/M/J/23 · Question 6May/June 2023Paper 226 marks
Loading question…
Question text

6
State three different features of a high-level programming language that a programmer could use
to make sure that their program will be easier to understand by another programmer.
Give an example for each feature.
Feature 1 …
…
Example …
…
Feature 2 …
…
Example …
…
Feature 3 …
…
Example …
…
[6]

Advertisement
84
2210/22/M/J/23 · Question 7May/June 2023Paper 2215 marks
Loading question…
Question text

7
An algorithm has been written in pseudocode to calculate a check digit for a four-digit number.
The algorithm then outputs the five-digit number including the check digit.
The algorithm stops when –1 is input as the fourth digit.
FALSE
01 Flag
02 REPEAT
0
03
Total
1 TO 4
04
FOR Counter
05
OUTPUT "Enter a digit ", Counter
06
INPUT Number[Counter]
Total + Number * Counter
07
Total
08
IF Number[Counter] = 0
09
THEN
TRUE
10
Flag
11
ENDIF
12
NEXT Counter
13
IF NOT Flag
14
THEN
MOD(Total, 10)
15
Number[5]
0 TO 5
16
FOR Counter
17
OUTPUT Number[Counter]
18
NEXT
19
ENDIF
20 UNTIL Flag
(a) Give the line number(s) for the statements showing:
Totalling …
Count-controlled loop …
Post-condition loop …
[3]
(b) Identify the three errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
[3]
(c) The algorithm does not check that each input is a single digit.
Identify the place in the algorithm where this check should occur.
Write pseudocode for this check.
Your pseudocode must make sure that the input is a single digit and checks for –1
Place in algorithm …
Pseudocode …
…
…
…
…
…
[4]

85
2210/22/M/J/23 · Question 11May/June 2023Paper 227 marks
Loading question…
Question text

11
The variables P and Q are used to store data in a program. P stores a string. Q stores a character.
(a) Write pseudocode statements to declare the variables P and Q, store "The world" in P and
store 'W' in Q
…
…
…
… [2]
(b) Write a pseudocode algorithm to:
•
convert P to upper case
•
find the position of Q in the string P (the first character in this string is in position 1)
•
store the position of Q in the variable Position
…
…
…
…
…
…
…
…
…
… [4]
(c) Give the value of Position after the algorithm has been executed with the data in
question 11(a).
…
… [1]

86
2210/22/M/J/23 · Question 12May/June 2023Paper 2215 marks
Loading question…
Question text

12 A two-dimensional (2D) array Account[] contains account holders’ names and passwords for a
banking program.
A 2D array AccDetails[] has three columns containing the following details:
•
column one stores the balance – the amount of money in the account, for example 250.00
•
column two stores the overdraft limit – the maximum total amount an account holder can
borrow from the bank after the account balance reaches 0.00, for example 100.00
•
column three stores the withdrawal limit – the amount of money that can be withdrawn at one
time, for example 200.00
The amount of money in a bank account can be negative (overdrawn) but not by more than the
overdraft limit.
For example, an account with an overdraft limit of 100.00 must have a balance that is greater than
or equal to –100.00
Suitable error messages must be displayed if a withdrawal cannot take place, for example if the
overdraft limit or the size of withdrawal is exceeded.
The bank account ID gives the index of each account holder’s data held in the two arrays.
For example, account ID 20’s details would be held in:
Account[20,1] and Account[20,2]
AccDetails[20,1] AccDetails[20,2] and AccDetails[20,3]
The variable Size contains the number of accounts.
The arrays and variable Size have already been set up and the data stored.
Write a program that meets the following requirements:
•
checks the account ID exists and the name and password entered by the account holder
match the name and password stored in Account[] before any action can take place
•
displays a menu showing the four actions available for the account holder to choose from:
1. display balance
2. withdraw money
3. deposit money
4. exit
•
allows an action to be chosen and completed. Each action is completed by a procedure
with a parameter of the account ID.
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 only need to declare any local arrays and local variables that you use.
You do not need to declare and initialise the data in the global arrays Account[] and
AccDetails[] and the variable Size
…
…
…
…
…
…
…
…
…
…
…
…

87
2210/22/O/N/22 · Question 1Oct/Nov 2022Paper 2220 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one constant you could have used for Task 1 and state its value.
Constant …
Value …
[2]
(ii)
Identify one array you could have used in Task 1 and describe its use.
Array …
Use …
…
…
[2]
(b) Describe how your program could validate the input for the day number within the two-week
period to make sure an appropriate value is entered (part of Task 1).
You must include programming statements as part of your answer.
…
…
…
…
…
…
…
…
…
…
…
… [3]
(c) Write an algorithm to show how your program allocates a parking space if the visitor requires
accessible parking (part of Task 2), including all relevant input and output, using pseudocode,
programming statements or a flowchart.
…
…
…
…
…

88
2210/22/O/N/22 · Question 2Oct/Nov 2022Paper 224 marks
Loading question…
Question text

2
Draw a line to connect each programming concept to the most appropriate description.
Programming concept
Description
carrying out an action multiple times within a loop
structure
counting
adding together the numbers in a list of numbers
repetition
tracking the number of iterations a program has
selection
performed in a loop
sequence
branching off to take a course of action depending
on the answer to a question
totalling
a set of statements to be executed in order
[4]

Advertisement
89
2210/22/O/N/22 · Question 4Oct/Nov 2022Paper 222 marks
Loading question…
Question text

4
Describe one type of test data that must be used to test if a program accepts valid input data.
…
…
…
… [2]

90
2210/22/O/N/22 · Question 5Oct/Nov 2022Paper 228 marks
Loading question…
Question text

5
This pseudocode should allow 500 marks to be entered into the algorithm. If the mark is 80 or
greater it is stored in an array for higher marks. If the mark is less than 80, but greater than or
equal to 50 it is stored in an array for middle marks. The remaining marks are stored in an array
for lower marks. The results from the algorithm are displayed at the end.
0
01
HighList
0
02
MidList
0
03
LowList
0
04
MarksEntry
05
REPEAT
06
INPUT Mark
07
IF Mark >= 80
08
THEN
MarksEntry
09
Higher[HighList]
HighList + 1
10
HighList
11
ELSE
12
IF Mark >= 50
13
THEN
Mark
14
Middle[MidList]
MidList
15
MidList
16
ELSE
Mark
17
Lower[HighList]
LowList + 1
18
LowList
19
ENDIF
20
ENDIF
MarksEntry + 1
21
MarksEntry
22
NEXT MarksEntry = 500
23
OUTPUT "You entered ", HighList, " higher marks"
24
OUTPUT "You entered ", MidList, " middle marks"
25
OUTPUT "You entered ", LowList, " lower marks"
(a) Identify the four errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) The corrected algorithm needs to be changed so that any number of marks may be entered
and the algorithm runs until the user tells it to stop.
Write the new pseudocode statements that would be needed to achieve this and state where
in the algorithm they would be placed.
…
…
…
…
…
…
…

Advertisement