Algorithm design and problem-solving – O Level Computer Science (2210)
137 questions · page 6 of 10
Question text
Tick ( ü ) one box in each row to identify if the statement is about validation, verification or both.
2
Verification
Both
Validation
Statement
( ü )
( ü )
( ü )
Entering the data twice to check if both entries are
the same.
Automatically checking that only numeric data has
been entered.
Checking data entered into a computer system
before it is stored or processed.
Visually checking that no errors have been
introduced during data entry.
[3]
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.
…
…
Question text
5
The flowchart represents an algorithm.
The algorithm will terminate if –1 is entered.
START
INPUT
Value
IS
Yes
Value =
–1 ?
OUTPUT
"Reject:
END
No
Abnormal"
IS
Value >= 50
No
AND Value
<= 100 ?
Yes
Diff1
100 – Value
Diff2
Value – 50
IS
No
OUTPUT
Diff1 < 1 OR
"Accept: Normal"
Diff2 < 1 ?
Yes
OUTPUT
"Accept:
Extreme"
(a) Complete the trace table for the input data:
50, 75, 99, 28, 82, 150, –1, 672, 80
Value
Diff1
Diff2
OUTPUT
[4]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) Identify and give the data type and use of one array that you could have used for Task 1.
Array …
Data type …
Use …
[3]
(b) Describe two validation checks that could be used when inputting the number of tickets to
buy for Task 2. For each validation check give one example of normal data and one example
of erroneous data.
Validation check 1 …
…
…
Normal data …
Erroneous data …
Validation check 2 …
…
…
Normal data …
Erroneous data …
[6]
(c) Write an algorithm for the part of Task 2 that inputs the tickets required, calculates the total
price for the ticket(s) purchased by a passenger including a group discount (if applicable) and
updates the data structures used for the totals.
Use either pseudocode, programming statements or a flowchart.
…
…
…
…
…
…
…
…
…
…
Question text
2
(a) Write an algorithm in pseudocode to input 500 positive whole numbers. Each number input
must be less than 1000. Find and output the largest number input, the smallest number input
and the range (difference between the largest number and smallest number).
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Describe how the algor
Question text
3
(a) Draw the most appropriate flowchart symbol for each pseudocode statement.
Pseudocode statement
Flowchart symbol
IF Number = 20
PRINT Number
← Number + 1
Number
[3]
← X + Y is totalling.
(b) State the type of each pseudocode statement. For example, X
IF Number = 20 …
PRINT Number …
← Number + 1 …
Number
[3]
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]
Question text
3
This pseudocode algorithm is used as a validation check.
PRINT "Input a number from 1 to 5000"
REPEAT
INPUT Number
IF Number < 1 OR Number > 5000
THEN
PRINT "Invalid number, please try again"
ENDIF
UNTIL Number >= 1 AND Number <= 5000
PRINT Number, " is within the correct range"
Identify three different types of test data. For each type, give an example of the test data you
would use to test this algorithm and state a reason for your choice of test.
Type of test data 1 …
Test data …
Reason …
…
Type of test data 2 …
Test data …
Reason …
…
Type of test data 3 …
Test data …
Reason …
…
[6]
Question text
4
This pseudocode algorithm allows 5000 numbers to be entered and stored in an array called
Number.
1 TO 5000
FOR Count
INPUT Number[Count]
NEXT Count
Extend and re-write the algorithm using pseudocode to also count and output how many of the
numbers stored in the array are greater than 500, using the variable Higher. Only output Higher
once with an appropriate message.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
Question text
5
This pseudocode represents an algorithm.
REPEAT
0
Flag
0 to 3
FOR Count
IF Num[Count] < Num[Count + 1]
THEN
Num[Count]
Store
Num[Count + 1]
Num[Count]
Store
Num[Count + 1]
1
Flag
ENDIF
NEXT Count
UNTIL Flag = 0
(a) The contents of the array at the start of the algorithm are:
Num[0]
Num[1]
Num[2]
Num[3]
Num[4]
45
56
30
12
15
Complete the trace table for the algorithm using the data given in the array.
Flag
Count
Num[0]
Num[1]
Num[2]
Num[3]
Num[4]
Store
45
56
30
12
15
[5]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]
Question text
6
Draw a flowchart symbol to represent each of the following:
Input/Output
Decision
[2]
Question 7 starts on Page 12.
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Question text
2
An algorithm has been written in pseudocode to check the temperature readings taken from a
freezer are within the range –18 degrees to –25 degrees inclusive.
The algorithm counts the number of times that the temperature reading is below –25 degrees and
the number of times that the temperature reading is above –18 degrees.
An engineer is called if there are more than 10 temperature readings below –25 degrees.
An alarm sounds if there are more than 5 temperature readings above –18 degrees.
0
01
TooHot
1000
02
TooCold
03
REPEAT
04
OUTPUT "Please enter temperature"
05
INPUT Temperature
06
IF Temperature < -25
07
THEN
TooCold – 1
08
TooCold
09
ENDIF
10
IF Temperature > -18
11
THEN
TooHot + 1
12
TooHot
13
ENDIF
14
UNTIL TooHot > 5 OR TooCold > 10
15
IF TooHot < 5
16
THEN
17
INPUT "Alarm!!"
18
ENDIF
19
IF TooCold > 10
20
THEN
21
OUTPUT "Call the Engineer"
22
ENDIF
(a) Give the line number(s) from the algorithm of:
an assignment statement …
a loop …
a counting statement …
a selection statement …
[4]
(b) Give line numbers where the four errors are to be found in the pseudocode. Suggest a
correction for each error.
Error 1 line number …
Correction …
…
Error 2 line number …
Correction …
…
Error 3 line number …
Correction …
…
Error 4 line number …
Correction …
…
[4]
(c) Explain how you could extend the algorithm to count the number of times the temperature
readings are within the range –18 degrees to –25 degrees inclusive.
…
…
…
…
Question text
4
This flowchart represents an algorithm that allows the input of two numbers and performs a
calculation.
The predefined function MOD finds the remainder from integer division for example X
8 MOD 5
gives X a value of 3.
START
INPUT
Y,Z
Yes
IS
END
Y = 0 ?
No
Yes
IS
A
Y MOD Z
Y > Z ?
No
A
Z MOD Y
IS
Yes
OUTPUT
A = 0 ?
"Valid"
No
OUTPUT
"Invalid"
(a) Complete a trace table for this set of input data:
11, 4, 6, 2, 3, 9, 3, 2, 2, 6, 0, 0, 1, 1
Y
Z
A
OUTPUT
[4]
(b) Explain the purpose of this algorithm.
…
…
…
… [2]
Question text
Tick ( ü ) one box in each row to identify if the statement about structure diagrams is true or false.
2
False
True
Statement
( ü )
( ü )
A structure diagram is a piece of code that is available throughout the
structure of a program.
A structure diagram shows the hierarchy of a system.
A structure diagram is another name for an array.
A structure diagram shows the relationship between different components
of a system.
[2]
Question text
3
Programs can perform validation and verification checks when data is entered.
(a) Give the names of two different validation checks and state the purpose of each one.
Check 1 …
Purpose …
…
…
Check 2 …
Purpose …
…
…
[4]
(b) Give the name of one verification check.
… [1]
(c) Describe the difference between validation and verification.
…
…
…
… [2]