Topical Pseudocodes, Flowcharts P2 O Level MT
Topical Pseudocodes, Flowcharts P2 O Level MT
(2210/21/M/J/15)
Q1/ Read this section of program code that should input 10 positive numbers and then
output the smallest number input.
1 Small = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Num = Small
6 Counter = Counter + 1
7 PRINT Small
8 UNTIL Counter < 10
There are four errors in this code. Locate these errors and suggest a corrected piece of
code for each error.
1..........................................................................................................................................
............................................................................................................................................
2..........................................................................................................................................
............................................................................................................................................
3.........................................................................................................................................
............................................................................................................................................
4..........................................................................................................................................
........................................................................................................................................[4]
............................................................................................................................................
........................................................................................................................................[2]
3. Identify three different loop structures that you can use when writing pseudocode.
1...........................................................................................................................
2...............................................................................................................................
3........................................................................................................................ [3]
4/- Five data types and five data samples are shown below.
Draw a line to link each data type to the correct data sample.
[4]
(2210/21/M/J/15)
5/- Read this section of program code that should input 30 positive numbers and then
output the largest number input.
1 Large = 9999
2 Counter = 0
3 WHILE Counter > 30
4 DO
5 INPUT Num
6 IF Num < Large THEN Large = Num
7 Counter = Counter - 1
8 ENDWHILE
9 PRINT Large
There are four errors in this code.
Locate these errors and suggest a corrected piece of code for each error.
1..........................................................................................................................................
2..........................................................................................................................................
3.........................................................................................................................................
4.....................................................................................................................................[4]
6/- Four programming concepts and four examples of programming code are shown below.
Draw a line to link each programming concept to the correct example of programming code.
[4]
(2210/21/M/J/16)
7/- Read this section of program code that inputs 10 positive numbers and then outputs
the smallest number input.
1 Small = 1000
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Small = Num
6 Counter = Counter + 1
7 UNTIL Counter = 10
8 PRINT Small
(i) Identify three changes you would need to make to find the largest number input instead
of the smallest number.
1 .........................................................................................................................................
...........................................................................................................................................
2 .........................................................................................................................................
...........................................................................................................................................
3 .........................................................................................................................................
.......................................................................................................................................[3]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
8/- A program will be written to store information about members of a swimming club.
The following membership details will be recorded:
Name
Gender
Status:
o Senior
o Junior
Fee
Team member (Yes or No)
(i) Choose a suitable data type for each of the membership details to be recorded.
[5]
State the data structure that would be most suitable to use and give a reason for your
choice.
Reason ...............................................................................................................................
.......................................................................................................................................[2]
9 The flowchart below inputs the height of children who want to ride on a rollercoaster. Children
under 1.2 metres are rejected. The ride starts when eight children have been accepted.
1.4, 1.3, 1.1, 1.3, 1.0, 1.5, 1.2, 1.3, 1.4, 1.3, 0.9, 1.5, 1.6, 1.0
Identify and describe two other types of loop structure that you could use when writing
pseudocode.
Description .................................................................................................................................
...................................................................................................................................................
Description .................................................................................................................................
...............................................................................................................................................[4]
2210/22/M/J/17
11(a) Write an algorithm to input three different numbers, and then output the largest number.
Use either pseudocode or a flowchart.
11b This flowchart inputs the weight of items in kilograms to be loaded on a trailer.
Any item over 25 kilograms is rejected.
The trailer can take up to 100 kilograms.
12 An algorithm has been written in pseudocode to input 100 numbers and print out the sum.
A REPEAT … UNTIL loop has been used.
Count ← 0
Sum ← 0
REPEAT
INPUT Number
Sum ← Sum + Number
Count ← Count + 1
UNTIL Count > 100
PRINT Sum
(a) Find the error in the pseudocode and suggest a correction.
Error ...........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................[2]
(b) Rewrite the correct algorithm using a more suitable loop structure.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
2210/22/M/J/18
13 (a) Draw a flowchart for an algorithm to input numbers. Reject any numbers that are negative
and count how many numbers are positive. When the number zero is input, the process ends
and the count of positive numbers is output.
[6]
(b) Explain the changes you will make to your algorithm to also count the negative numbers.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
14 This pseudocode algorithm inputs two non-zero numbers and a sign, and then
performs the
calculation shown by the sign. An input of zero for the first number terminates the
process.
[3]
(b) Show how you could improve the algorithm written in pseudocode by writing an alternative
type of conditional statement in pseudocode.
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
...........................................................................................................................................
............................................................................................................................................
.......................................................................................................................................[3]
15 A programmer has written a routine to store the name, email address and password of a
contributor
to a website’s discussion group.
(a) The programmer has chosen to verify the name, email address and password.
Explain why verification was chosen and describe how the programmer would verify this data.
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
............................................................................................................................................
...........................................................................................................................................
............................................................................................................................................
.......................................................................................................................................[4]
(b) The programmer has also decided to validate the email address and the password.
Describe validation checks that could be used.
16 A program checks that the weight of a basket of fruit is over 1.00 kilograms and under
1.10 kilograms. Weights are recorded to an accuracy of two decimal places and any weight not
in this form has already been rejected.
Give three weights as test data and for each weight state a reason for choosing it.
All your reasons must be different.
Weight 1:
............................................................................................................................................
Reason
..............................................................................................................................................
.........................................................................................................................................................
.
Weight 2:
............................................................................................................................................
Reason
:..............................................................................................................................................
.........................................................................................................................................................
Weight 3:
............................................................................................................................................
Reason
:..............................................................................................................................................
................................................................................................................................................... [3]
2210/22/M/J/19
17 (a) An algorithm has been written in pseudocode to input 100 numbers, select and print the
largest number and smallest number.
Count 1
INPUT Number
High Number
Low Count
REPEAT
INPUT Number
IF Number > High
THEN
High Number
ENDIF
Find 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) Show how you would change the corrected algorithm to total the numbers and print the total.
Use a variable Total.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
18 This flowchart inputs the marks gained in an examination. An input of –1 ends the routine.
Complete the trace table for the mark input data: 50, 70, 65, 30, 95, 50, 55, 85, 65, 35, –1, 45
[4]
19 (a) For each of the four groups of statements in the table, place a tick in the correct column
to show whether it is an example of Selection or Repetition.
20 (a)
(b) Using a single loop, write an algorithm in pseudocode to output 50 names that have been
stored in the array, Name[ ]
....................................................................................................................................................
....................................................................................................................................................
....................................................................................................................................................
....................................................................................................................................................
....................................................................................................................................................
................................................................................................................................................[3]
2210/02/SP/23
21 (a
21 (a) The array Name[1:4] used in the flowchart contains the following data:
Complete the trace table using the data given in the array.
....................................................................................................................................................
....................................................................................................................................................
....................................................................................................................................................
............................................................................................................................................... [2]
2210/02/SP/23
(MARKING KEY)
[4]
(2210/21/M/J/15)
5/- mark for each error identified + suggested correction.
Line 1 or Large =9999: this should read Large = 0
Line 3 or WHILE: this should read WHILE Counter < 30
Line 6 or IF: this should read IF Num > Large THEN Large = Num
Line 7 or Counter =…: this should read Counter = Counter + 1 [4]
6/- 1 mark for each correct line, two lines from one box not allowed
[4]
(2210/MJ/21/16)
7. (i) 1 mark for each change
1 Large = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num > Large THEN Large = Num
6 Counter = Counter + 1
7 UNTIL Counter = 10
8 PRINT Large
[3]
8 (i)
Name type – string
Gender type – char/string
Status type – char/string
Fee type – real
Team member type – Boolean [5]
– WHILE (… DO … ENDWHILE) …
– … used where the loop may never be executed/whilst a specified condition exists
[4]
11
11 (b)
12(a)
Error - Count 0
Correction - Count 1
or
Error - UNTIL Count > 100
Correction - UNTIL Count >= 100 or UNTIL Count = 100
or
UNTIL Count > 99
2
12(b)
– use of FOR with correct start and end values
- use of NEXT
- removal of increment for Count
Sample algorithm
Sum 0
FOR Count 1 TO 100
INPUT Number
Sum Sum + Number
NEXT // NEXT Count
PRINT Sum 3
13 (a)
• Update this counter/variable when the number is less than zero/count all
numbers and subtract the positive numbers
• Output this counter/variable at the end // Output both counters at the end
[2]
14 (a)
14(b)
CASE Sign OF
ENDCASE (1)
Example CODE
CASE Sign OF
ꞌ+ꞌ : Answer ← Number1 + Number2
ꞌ-ꞌ : Answer ← Number1 - Number2
ꞌ*ꞌ : Answer ← Number1 * Number2
ꞌ/ꞌ : Answer ← Number1 / Number2
OTHERWISE Answer ← 0
ENDCASE
[3]
15(a) Max 4 in total
Any 3 from:
• To ensure no changes are made on input / accuracy of transcription
• Because the details do not have fixed, values or lengths to validate
• Because there is no clear set of rules that can be used for validation
Any 3 from:
• The programmer could ask the contributor to type in each detail twice
• and then check that both values are equal
• If they are not equal then the input should be rejected
• The programmer could ask the contributor to check the details on the screen
• and confirm that they are correct / same as the original
• or change them
[4]
15(b) One mark for email and one mark for password
check // length check (not more than 254 characters) // uniqueness check
Password – length check / numbers and letters etc. // uniqueness check not been
used before // presence check
[2]
16
Max 4 in total
Any 3 from:
To ensure no changes are made on input / accuracy of transcription
Because the details do not have fixed, values or lengths to validate
Because there is no clear set of rules that can be used for validation
Any 3 from:
The programmer could ask the contributor to type in each detail twice
and then check that both values are equal
If they are not equal then the input should be rejected
The programmer could ask the contributor to check the details on the
screen
and confirm that they are correct / same as the original
or change them
4
4(b) One mark for email and one mark for password
Email – check for @ / format check / no spaces /valid characters // presence
check // length check (not more than 254 characters) // uniqueness check
Password – length check / numbers and letters etc. // uniqueness check not been
used before // presence check
2
17
(a) mark for each error identified + suggested correction
Low ← Count should be Low ← Number
Number > Low should be Number < Low
UNTIL Count = 99 should be UNTIL Count > 99 or UNTIL
Count = 100 or UNTIL Count >= 100 // Count ← 1
should be Count ← 0
PRINT "Largest Number is ", Number should be PRINT
"Largest Number is ", High
4
(b) MP1 Add Total ← 0 // Total ← Number
MP2 Add Total ← Total + Number
MP3 Add PRINT "Total is ", Total
Count ← 1
INPUT Number
High ← Number
Low ← Number
Total ← Number
REPEAT
INPUT Number
Total ← Total + Number
IF Number > High
THEN
High ← Number
ENDIF
IF Number < Low
THEN
Low ← Number
ENDIF
Count ← Count + 1
UNTIL Count > 99
PRINT "Largest Number is ", High
PRINT "Smallest Number is ", Low
PRINT "Total is ", Total
4
18
19 (a)
19 (b)
Validation Two from:
automated checking
checking that data is reasonable / of a certain type
checking that data meets certain criteria Example 1 mark
range check // length check // type check // check digit etc.
Verification Two from:
checking that data has not changed
during input to a computer
during transfer between computers / devices Example 1 mark
double entry // checking against original // visual check // use of checksum etc.
20 (a)
20 (b)
21 (a)
[5]
21(b)
• bubble sort / sorting the names
• ascending order / A to Z / lowest to highest / alphabetical order [2]
22