Programming – O Level Computer Science (2210)

174 questions · page 7 of 12 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
91
2210/22/O/N/22 · Question 6Oct/Nov 2022Paper 225 marks
Loading question…
Question text

6
This flowchart represents an algorithm to divide three-digit numbers into hundreds, tens and units.
The pre-defined function DIV gives the value of the result of integer division, for example
Y = 9 DIV 4 gives the value Y = 2
The pre-defined function MOD gives the value of the remainder of integer division, for example
R = 9 MOD 4 gives the value R = 1
START
Counter
0
Counter
Counter + 1
IS
Yes
Counter > 7?
No
INPUT
Number
IS
Yes
Number < 100?
No
IS
Yes
Number > 999?
No
Hundreds
Number DIV 100
Temp
Number MOD 100
Tens
Temp DIV 10
Units
Number MOD 10
STOP
OUTPUT "Hundreds: ",
Hundreds, " Tens: ",
Tens, " Units: ", Units
Complete the trace table for the algorithm using this input data:
97, 876, 4320, 606, 9875, 42, 124
Counter
Number
Hundreds
Temp
Tens
Units
OUTPUT
[5]

92
2210/23/O/N/22 · Question 1Oct/Nov 2022Paper 2320 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one constant that you could have used for Task 1.
State the value that would be assigned to the constant.
Give a reason why a constant was used rather than a variable.
Constant name …
Value …
Reason …
…
…
[3]
(ii)
Describe the array that you set up in Task 1 to record the customer details.
Include the name, data type and sample data for the array in your description.
…
…
…
…
…
… [3]
(b) Explain how your program allowed only two floors or three floors to be chosen but not both.
…
…
…
…
…
… [3]
(c) Write an algorithm for the part of Task 2 that calculates the total cost of the bill.
Assume that the customer details and services required have already been input.
Use pseudocode, programming statements or a flowchart.
…
…
…
…
…
…

93
2210/23/O/N/22 · Question 2Oct/Nov 2022Paper 239 marks
Loading question…
Question text

2
An algorithm has been written to:
•
set all 50 elements of the array Reading[1:50] to zero
•
input values between 35 and 50 inclusive
•
end the process when an input of –1 is made or 50 valid numbers have been entered
•
reject all other values
•
count the number of times each valid value is input
•
output the number of times each value has been input, starting with the lowest value.
(a) Complete the pseudocode algorithm:
1 TO …
01
FOR Count
0
02
Reading[Count]
03
NEXT Count
1
04
Count
05
OUTPUT "Please enter next reading "
06
INPUT Value
07
REPEAT
IF Value < 35 OR …
08
09
THEN
10
OUTPUT "Reading out of range"
11
ELSE
…
12
Reading[Value]
13
Count = Count + 1
14
ENDIF
15
IF Count <= 50
16
THEN
17
OUTPUT "Please enter next reading "
…
18
19
ENDIF
20
UNTIL Value = -1 OR Count > 50
35
21
Count
22
REPEAT
OUTPUT "There are ", … ,
23
" readings of ", Count
…
24
Count
[6]
25
UNTIL Count > 50
(b) Describe how the algorithm could be changed to output the number of times each value has
been input, starting with the highest value.
…
…
…
…
…
… [3]

Advertisement
94
2210/21/M/J/22 · Question 1May/June 2022Paper 2120 marks
Loading question…
Question text

1
(a) Describe the data structures you could have used in Task 1. Your description should include
types of data structure, names used for data structures, their uses and examples of sample
data.
…
…
…
…
…
…
…
…
…
… [5]
(b) Explain how you could change your program in Task 1 to total all the money collected from
new members who have paid.
…
…
…
…
…
… [3]
(c) Describe how data input in Task 1 could be validated to find out if a new member wants to
work as a volunteer.
…
…
…
…
…
… [3]
(d) Write an algorithm to show how your program completes Task 3 assuming the option to
sponsor a wooden plank has been chosen, using pseudocode, programming statements or a
flowchart. Details completed in Task 1 are not required.
…

95
2210/21/M/J/22 · Question 2May/June 2022Paper 214 marks
Loading question…
Question text

Tick ( ü ) one box in each row to identify the most appropriate data type for each description. Only
2
one tick ( ü ) per column.
Data type
Description
Boolean
Char
Integer
Real
String
a single character from the keyboard
multiple characters from the keyboard
only one of two possible values
only whole numbers
any number
[4]

96
2210/21/M/J/22 · Question 5May/June 2022Paper 217 marks
Loading question…
Question text

5
The pseudocode represents an algorithm.
The pre-defined function DIV gives the value of the result of integer division.
For example, Y = 9 DIV 4 gives the value Y = 2
The pre-defined function MOD gives the value of the remainder of integer division.
For example, R = 9 MOD 4 gives the value R = 1
←
0
First
←
0
Last
INPUT Limit
←
1 TO Limit
FOR Counter
INPUT Value
IF Value >= 100
THEN
IF Value < 1000
THEN
←
Value DIV 100
First
←
Value MOD 10
Last
IF First = Last
THEN
OUTPUT Value
ENDIF
ENDIF
ENDIF
NEXT Counter
(a) Complete the trace table for the algorithm using this input data:
8, 66, 606, 6226, 8448, 642, 747, 77, 121
Counter
Value
First
Last
Limit
OUTPUT
[5]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]

97
2210/22/M/J/22 · Question 1May/June 2022Paper 2220 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one constant that you could have used for Task 1.
Give the value and use of the constant.
Constant …
Value …
Use …
…
[3]
(ii)
Identify one variable that you could have used for Task 2.
Give the data type and use of the variable.
Variable …
Data type …
Use …
…
[3]
(b) Explain how your program showed the days available for booking in Task 1.
…
…
…
…
…
… [3]
(c) Explain how your program made sure that each booking number allocated in Task 2 was
unique.
…
…
…
… [2]
(d) Write an algorithm for the part of Task 2 that inputs the tickets and extra attractions required
then calculates the total cost of the booking.
Assume that the booking is for a single day.
Use pseudocode, programming statements or a flowchart.
…
…
…
…
…

98
2210/22/M/J/22 · Question 2May/June 2022Paper 2211 marks
Loading question…
Question text

2
An algorithm allows a user to input their password and checks that there are at least eight
characters in the password. Then, the user is asked to re-input the password to check that both
inputs are the same. The user is allowed three attempts at inputting a password of the correct
length and a matching pair of passwords. The pre-defined function LEN(X) returns the number of
characters in the string, X
←
0
01
Attempt
02
REPEAT
←
TRUE
03
PassCheck
04
OUTPUT "Please enter your password "
05
INPUT Password
06
IF LEN(Password) < 8
07
THEN
←
TRUE
08
PassCheck
09
ELSE
10
OUTPUT "Please re-enter your password "
11
INPUT Password2
12
IF Password <> Password
13
THEN
←
FALSE
14
PassCheck
15
ENDIF
16
ENDIF
←
Attempt + 1
17
Attempt
18
UNTIL PassCheck OR Attempt <> 3
19
IF PassCheck
20
THEN
21
OUTPUT "Password success"
22
ELSE
23
OUTPUT "Password fail"
24
ENDIF
(a) Identify the three errors in the pseudocode and suggest a correction to remove each error.
Error 1 …
Correction …
Error 2 …
Correction …
Error 3 …
Correction …
[3]
(b) The algorithm includes two types of check on the data input.
Identify and describe each type of check.
Type of check 1 …
Description …
…
Type of check 2 …
Description …
…
[4]
(c) Give two sets of test data for this algorithm and a reason for choosing each set.
Each set of test data and its reason must be different.
Set 1 …
Reason …
…
Set 2 …
Reason …
…
[4]

Advertisement
99
2210/22/M/J/22 · Question 3May/June 2022Paper 225 marks
Loading question…
Question text

3
(a) Describe a one-dimensional array. Include an example of an array declaration.
…
…
…
…
…
… [3]
(b) Explain how indexing could be used to search for a value stored in a one-dimensional array.
…
…
…
… [2]

100
2210/22/O/N/21 · Question 1Oct/Nov 2021Paper 2220 marks
Loading question…
Question text

1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one variable you could have used for Task 2 and state its use.
Variable …
Use …
…
…
[2]
(ii)
Describe the arrays you could have used in Task 1. Include the name, data type, use
and sample data for each array.
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Describe how you could validate the data entry for the input of the codes for the different
stages of the journey in Task 2.
…
…
…
…
…
… [3]
(c) Write an algorithm to show how your program carries out Task 3, using either pseudocode,
programming statements or a flowchart. Assume Tasks 1 and 2 have already been completed.
…
…

101
2210/22/O/N/21 · Question 4Oct/Nov 2021Paper 2210 marks
Loading question…
Question text

4
The pseudocode algorithm should work as a calculator and output the result.
1
1 Continue
2 WHILE Continue = 0
3
OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /"
4
INPUT Operator
5
OUTPUT "Enter the first value"
6
INPUT Value1
7
OUTPUT "Enter the second value"
8
OUTPUT Value2
9
IF Operator
Value1 + Value2
10
1: Answer
Value1 - Value2
11
2: Answer
Value1 * Value2
12
3: Answer
Value1 / Value2
13
4: Answer
14
ENDCASE
15
OUTPUT "The answer is ", Value1
16
OUTPUT "Do you wish to enter more values (Yes or No)?"
17
INPUT MoreValues
18
IF MoreValues = "No"
19
THEN
1
20
Continue
21
ENDIF
22 UNTIL Continue = 0
(a) Find the five errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
Error 5 …
Correction …
…
[5]
(b) The algorithm needs changing to allow only the numbers 1, 2, 3, or 4 to be entered for the
input variable Operator.
Write the pseudocode to perform this task and state where in the algorithm it would be
located.
Pseudocode …
…
…
…
…
…
…

102
2210/21/M/J/21 · Question 1May/June 2021Paper 2120 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers must have meaningful names.
(i)
Identify one constant you could have used for Task 1, give the value that would be
assigned to it and its use.
Constant …
Value …
Use …
…
…
[3]
(ii)
Identify one variable and one array you could have used for Task 1.
Explain the use of each one.
Variable …
Use …
…
…
Array …
Use …
…
…
[4]
(b) Explain how you should change your program in Task 1 to allow a tutor to enter up to eight
candidates for the election.
…
…
…
…
…
…
…
… [4]
(c) Write an algorithm using pseudocode, programming statements or a flowchart to show how
your program completes these parts of Task 2:
•
Allows students to enter their unique voter number before casting their vote.
•
Checks whether the student has already voted:
– if so, supplies a suitable message and does not allow them to vote.
– if not, stores the unique voter number, but not their vote, in a suitable data structure.
It is not necessary to show parts completed in Task 1, including counting of votes for each
candidate.
…

103
2210/21/M/J/21 · Question 3May/June 2021Paper 216 marks
Loading question…
Question text

3
Name and describe the most appropriate programming data type for each of the examples of data
given. Each data type must be different.
Data: 37
Data type name …
Data type description …
…
…
Data: Cambridge2021
Data type name …
Data type description …
…
…
Data: 47.86
Data type name …
Data type description …
…
…
[6]

Advertisement
104
2210/21/M/J/21 · Question 4May/June 2021Paper 219 marks
Loading question…
Question text

4
The pseudocode algorithm shown has been written by a teacher to enter marks for the students in
her class and then to apply some simple processing.
←
0
Count
REPEAT
INPUT Score[Count]
IF Score[Count] >= 70
THEN
←
"A"
Grade[Count]
ELSE
IF Score[Count] >= 60
THEN
←
"B"
Grade[Count]
ELSE
IF Score[Count] >= 50
THEN
←
"C"
Grade[Count]
ELSE
IF Score[Count] >= 40
THEN
←
"D"
Grade[Count]
ELSE
IF Score[Count] >= 30
THEN
←
"E"
Grade[Count]
ELSE
←
"F"
Grade[Count]
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
←
Count + 1
Count
UNTIL Count = 30
(a) Describe what happens in this algorithm.
…
…
…
…
…
…
…
… [3]
(b) Write the pseudocode to output the contents of the arrays Score[] and Grade[] along with
suitable messages.
…
…
…
…
…
…
…
…
…
…
…
… [3]
(c) Describe how you could change the algorithm to allow teachers to use it with any size of
class.
…
…

105
2210/22/M/J/21 · Question 4May/June 2021Paper 227 marks
Loading question…
Question text

4
This algorithm checks passwords.
•
Each password must be 8 or more characters in length; the predefined function Length
returns the number of characters.
•
Each password is entered twice, and the two entries must match.
•
Either Accept or Reject is output.
•
An input of 999 stops the process.
REPEAT
OUTPUT "Please enter password"
INPUT Password
IF Length(Password) >= 8
THEN
INPUT PasswordRepeat
IF Password <> PasswordRepeat
THEN
OUTPUT "Reject"
ELSE
OUTPUT "Accept"
ENDIF
ELSE
OUTPUT "Reject"
ENDIF
UNTIL Password = 999
(a) Complete the trace table for the algorithm using this input data:
Secret, Secret, VerySecret, VerySecret, Pa55word, Pa55word, 999, 888
Password
PasswordRepeat
OUTPUT
[3]
(b) Explain how the algorithm could be extended to allow three attempts at inputting the matching
password. Any pseudocode statements used in your answer must be fully explained.
…
…
…
…
…
…
…
… [4]

Advertisement