Pseudocode Topicals
Pseudocode Topicals
Q. Describe each of the following data types used in programming. In each case,
give an example of a piece of data to illustrate your answer. Each example must
be different.
• Char
• String
• Boolean [6] (Q2/21/M/J/19)
Ans.
Many possible answers, those given are examples only.
1 mark for each correct description and 1 mark for each correct example
Char
Description: A single character (from the keyboard)
Example: A / # / 2
String
Description: An (ordered) sequence of characters
Example: Hello world / #123?Y / 234 78963
Boolean
Description: A data type with two possible values
Example: TRUE / FALSE
Q.
a) Give an example of a conditional statement using pseudocode. [2]
b) Describe the purpose of a conditional statement. [2] (Q3/21/M/J/19)
Ans.
a) Many possible answers, those given are examples only.
1 mark per bullet:
• IF
• Condition and outcome
Example answer:
IF X < 0
THEN
PRINT "Negative"
ELSE
PRINT "Not negative"
ENDIF
OR
1 mark per bullet:
• CASE
• Condition and outcome
Example answer:
CASE X OF
1: PRINT ("ONE")
2: PRINT ("TWO")
OTHERWISE PRINT ("Less than ONE or more than TWO")
ENDCASE
b) • To allow different routes through a program
• dependent on meeting certain criteria
2210 Page 1
5 INPUT Value
6 ENDWHILE
7 PRINT "Accepted: ", Value
c) Complete the trace table for this program code using the test data: 200, 300, –1,
50, 60 [3] (Q4c/21/M/J/19)
Value OUTPUT
Ans.
c) 1 mark – Value column
1 mark – OUTPUT column first line
1 mark – OUTPUT column lines two to five
2210 Page 2
Count ← Count + 1
UNTIL Count = 50
One mark – separate INPUT statement
One mark – IF statement attempted
One mark – IF statement completely correct
One mark – termination of loop updated
c) Any two correct statements (max two) e.g.
• Alter the IFstatement/add a second IF statement/comparison that’s already
there …
• … so that additional criteria set an upper limit of <=200
Q. Most programming languages include basic data types. Ahmad is describing the
basic data types he has used.
State the data type that Ahmad is describing in each sentence.
Array Boolean Char Constant Function Imteger
Iteration Procedure Real String Variable
A number with a fractional part that can be positive or negative and used in
calculation
Data type ..........................................................................................................
A whole number that can be positive, negative or zero and used in calculations
Data type ..........................................................................................................
A single number, symbol or letter
Data type ..........................................................................................................
A sequence of characters
Data type ..........................................................................................................
A data type with two values, True or False
Data type ..........................................................................................................
[5] (Q2/22/M/J/20)
Ans.
Real
Integer
Char/String
String
Boolean
Q. An algorithm has been written in pseudocode to input the names and marks of
35 students.
The algorithm stores the names and marks in two arrays Name[ ] and Mark[ ].
The highest mark awarded is found and the number of students with that mark
is counted. Both of these values are output.
01 HighestMark ← 100
02 HighestMarkStudents ← 0
03 FOR Count ← 1 TO 35
04 OUTPUT "Please enter student name"
05 INPUT Name[Count]
06 OUTPUT "Please enter student mark"
07 INPUT Mark[Counter]
08 IF Mark[Count] = HighestMark
09 THEN
10 HighestMarkStudents ← HighestMarkStudents – 1
11 ENDIF
12 IF Mark[Count] > HighestMark
13 THEN
14 Mark[Count] ← HighestMark
15 HighestMarkStudents ← 1
16 ENDIF
17 NEXT Count
2210 Page 3
17 NEXT Count
18 OUTPUT "There are ", HighestMarkStudents," with the highest mark of ",
HighestMark
a) 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]
b) Explain how you could extend the algorithm to also find the lowest mark
awarded, count the number of students with that mark, and output both these
values. [6] (Q3/22/M/J/20)
Ans.
a) One mark for error and correction
Line 1 HighestMark ← 0
Line 7 INPUT Mark[Count]
Line 10 HighestMarkStudents ← HighestMarkStudents + 1
Line 14 HighestMark ← Mark[Count]
b) Any six from:
Add variable LowestMark …
… Set this to a high value for example 100
Add variable LowestMarkStudents …
… Set this to zero
Check if Mark[Count] = LowestMark …
… True – add 1 to LowestMarkStudents
Check if Mark[Count] < LowestMark …
… True – set LowestMarkStudenta to 1 and set LowestMark to Mark[Count]
Add extra output statement
Q. Arrays are data structures used in programming. Explain what is meant by the
terms dimension and index in an array. Use examples of arrays in your
explanations. [3] (Q5/22/M/J/20)
Ans.
One mark for explanation of dimension
One mark for explanation of index
One mark for inclusion of an example
The dimension is the number of indexes required to access an element. The index
is the position of the element in an array
For example A[25] is the 25th element of a one-dimensional array.
2210 Page 4
(Q4/22/O/N/20)
Ans.
Any six from:
MP1 Initialisation of Higher to 0 before the loop
MP2 Use of IF statement
MP3 Correct condition in IF statement
MP4 Correct counting statement inside loop
MP5 OUTPUT/PRINT statement with correct reference to Higher
MP6 Appropriate message in output
MP7 Correct location of OUTPUT and IF statements
Higher ← 0
FOR Count ← 1 TO 5000
INPUT Number[Count]
IF Number[Count] > 500
THEN Higher ← Higher + 1
ENDIF
NEXT Count
OUTPUT "There are ", Higher, " values that are greater than 500"
2210 Page 5
b) Give line numbers where the four errors are to be found in the pseudocode.
Suggest a correction for each error. [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. [4] (Q2/23/O/N/20)
Ans.
a) Line 1/2/8/12
Line 3 and/or 14
Line 8/12
Line 6/10/15/19
b) One mark for error and correction
Line 02 TooCold ← 0
Line 08 TooCold ← TooCold + 1
Line 15 IF TooHot > 5
Line 17 OUTPUT "Alarm!!"
c) Any four from:
Add a new variable inRange …
… set to zero at start of algorithm
Add extra IF statement
IF temperature >= -25 AND temperature <= -18
Update inRange by 1 if true
2210 Page 6
Q.
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 [3]
Password PasswordRepeat OUTPUT
2210 Page 7
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] (Q4/22/M/J/21)
Ans.
a) One mark for each correct column
Q.
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]
2210 Page 8
number and smallest number). [6]
b) Describe how the algorithm could be changed to make testing less time-
consuming. [2] (Q2/22/M/J/21)
Ans.
a) Any six from:
MP1 Initialisation of large and small variables e.g. Large ← 0 Small ← 1000
MP2 Use of a loop for 500 entries // or 499 if initialisation done on first correct
entry
MP3 Input with prompt
MP4 Attempt at checking the range of 1 to 999 for input
MP5 … working range check
MP6 Checking for a whole number
MP7 Selecting largest number
MP8 Selecting smallest number
MP9 Calculating the range
MP10 Outputting the largest, smallest and range with message
Large ← 0
Small ← 1000
FOR Count ← 1 TO 500
REPEAT
OUTPUT "Enter a whole number between 1 and 999"
INPUT Number
UNTIL Number >= 1 AND Number < 1000 AND Number = Number DIV 1
IF Number < Small
THEN
Small <-- Number
ENDIF
IF Number > Large
THEN
Large ← Number
ENDIF
NEXT
Range ← Large – Small
OUTPUT "Largest number is ", Large, " Smallest number is ", Small, " Range of
numbers is ", Range
b) One mark for action required and one mark for method used
Reduce the amount of numbers entered
By decreasing the final value of the loop
or
Remove the need to input values
By using random numbers / a previously populated array
2210 Page 9
Ans.
a) One mark for:
• Use of FOR loop
• Working loop with correct number of Iterations
• Correct assignment
FOR Count ← 1 TO 20
dataArray[Count] ← 0
NEXT (Count)
b) (A FOR loop has) a fixed number of repetitions // No need to manage the loop
counter // no need to use another variable for the array index
Q. 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](Q3/21/M/J/21)
Ans. One mark per bullet point
37
• Data type name Integer
• Data type description (Any) whole number
Cambridge2021
• Data type name String
• Data type description A group of characters/text
47.86
• Data type name Real
• Data type description (Any real) number that could be a whole number or a
fraction
Q. 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.
2210 Page 10
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. [3] (Q4/21/M/J/21)
Ans.
a) One mark per mark point (Max 3)
• MP1 Marks input are stored in the array Score[]
• MP2 Marks are checked against a range of boundaries // allow example
• MP3 … and a matching grade is assigned to each mark that has been input
• MP4 … then stored in the array Grade[]…
• MP5 … at the same index as the mark input
• MP6 The algorithm finishes after 30 marks have been input // allows 30 scores to
be entered
b) One mark per mark point (Max 3)
• MP1 Correct loop, including counter if not a FOR loop
• MP2 Correct output of Score[ ]
• MP3 Correct output of Grade[ ]
• MP4 Suitable messages/text in output for both arrays
Example answers
Count ← 0
REPEAT
PRINT "Student: ", Count, " Mark: ", Score[Count], " Grade: ",Grade[Count]
2210 Page 11
PRINT "Student: ", Count, " Mark: ", Score[Count], " Grade: ",Grade[Count]
Count ← Count + 1
UNTIL Count = 30
Count ← 0
WHILE Count < 30 DO
PRINT "Student: ", Count, " Mark: ", Score[Count], " Grade: ",Grade[Count]
Count ← Count + 1
ENDWHILE
FOR Count ← 0 TO 29
PRINT "Student: ", Count, " Mark: ", Score[Count], " Grade: ", Grade[Count]
NEXT
c) Any three correct statements (Max 3) e.g.
• MP1 Add an input facility to allow teachers to enter the class size
• MP2 Add a variable to store the input class size
• MP3 Use the class size variable as the terminating condition for the loop
• MP4 Make sure the arrays are sufficiently large to accommodate the largest
possible class size
Q. The pseudocode algorithm should work as a calculator and output the result.
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]
2210 Page 12
[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 ........................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
Location in algorithm ..........................................................................................
............................................................................................................................
............................................................................................................................
[5] (Q4/22/O/N/21)
Ans.
a) One mark for error identified and suggested correction (Max three)
Line 8 OUTPUT Value2 – should be INPUT Value2
Line 9 IF Operator – should be CASE OF Operator
Line 15 OUTPUT "The answer is ", Value1 – should be Answer
One mark for error identified and suggested correction (Max two)
Method 1
Line 1 Continue ← 1 should be Continue ← 0
Line 22 UNTIL Continue = 0 should be ENDWHILE // Line 2 WHILE Continue = 0
should be REPEAT and Line 22 UNTIL Continue = 0 should be Until Continue = 1
OR
Method 2
Line 2 WHILE Continue = 0 should be REPEAT
Line 20 Continue ← 1 should be Continue ← 0 // Line 1 Continue ← 1 should be
Continue ← 0 and Line 22 UNTIL Continue = 0 should be Until Continue = 1
OR
Method 3
2210 Page 13
ENDWHILE
Alternative answer.
Week
REPEAT IF Operator < 1 OR Operator > 4 THEN OUTPUT "Enter 1, 2, 3 or 4"
INPUT Operator ENDIF UNTIL Operator >= 1 AND Operator <= 4 One mark After
line 4 / between lines 2 and 5
Q. Tick (✅) one box in each row to identify the most appropriate data type for
each description. Only one tick (✅) per column. [4] (Q2/21/M/J/22)
Ans.
Q. Write a pseudocode routine that will check that each test result entered into
the algorithm is between 0 and 100 inclusive. [4] (q4b/21/M/J/22)
Ans. One mark per mark point, max four
• MP1 appropriate conditional loop structure
• MP2 correct identification of invalid input
• MP3 appropriate error message
• MP4 repeated input of score until correct
WHILE Score < 0 OR Score > 100 (DO)
OUTPUT "Your entry must be between 0 and 100, inclusive, please try again "
INPUT Score
ENDWHILE
Or:
REPEAT
IF Score < 0 OR Score > 100
THEN OUTPUT "Your entry must be between 0 and 100, inclusive, please try again "
INPUT Score
ENDIF
UNTIL Score >= 0 AND Score <= 100
2210 Page 14
Last ← 0
INPUT Limit
FOR Counter ← 1 TO Limit.
INPUT Value.
IF Value >= 100.
THEN
IF Value < 1000.
THEN
First ← Value DIV 100
Last ← Value MOD 10
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
[5]
b) Describe the purpose of the algorithm.[2] (Q5/21/M/J/22)
Ans.
a) One mark per mark point, max five
• MP1 correct counter and limit column
• MP2 correct value column
• MP3 correct first column
• MP4 correct last column
• MP5 correct OUTPUT
2210 Page 15
b) One mark per mark point, max two
• checks for / outputs 3-digit numbers
• ....where the first digit and the last digit are the same
Q. 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.
01 Attempt ← 0
02 REPEAT
03 PassCheck ← TRUE
04 OUTPUT "Please enter your password "
05 INPUT Password
06 IF LEN(Password) < 8
07 THEN
08 PassCheck ← TRUE
09 ELSE
10 OUTPUT "Please re-enter your password "
11 INPUT Password2
12 IF Password <> Password
13 THEN
14 PassCheck ← FALSE
15 ENDIF
16 ENDIF
17 Attempt ← Attempt + 1
18 UNTIL PassCheck OR Attempt <> 3
19 IF PassCheck
20 THEN
21 OUTPUT "Password success"
22 ELSE
23 OUTPUT "Password fail"
2210 Page 16
23 OUTPUT "Password fail"
24 ENDIF
a) Identify the three errors in the pseudocode and suggest a correction to remove
each error. [3] (q2a/22/M/J/22)
Ans. One mark per mark point, max three
• line 8 / PassCheck ← TRUE
correction: PassCheck ← FALSE
• line 12 / IF Password <> Password
correction: IF Password2 <> Password // IF Password <> Password2
• line 18 / UNTIL PassCheck OR Attempt <> 3
correction: UNTIL PassCheck OR Attempt = 3 / UNTIL PassCheck OR Attempt >= 3
Q.
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] (q3/22/M/J/22)
Ans.
a) One mark per mark point, max two
• a list / one column of items
• … of the same data type
• … stored under a single identifier
• … with a single index to identify each element
One mark for an example of a declaration
• example e.g. DECLARE MyArray : ARRAY[1:10] OF INTEGER
b) One mark per mark point, max two
• using a counter to index the array
• so that the same code can be repeatedly used to check every element // every
element can be checked in a loop
2210 Page 17
Q. 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.
01 HighList <-- 0
02 MidList <-- 0
03 LowList <-- 0
04 MarksEntry <-- 0
05 REPEAT
06 INPUT Mark
07 IF Mark >= 80
08 THEN
09 Higher[HighList] <-- MarksEntry
10 HighList <-- HighList + 1
11 ELSE
12 IF Mark >= 50
13 THEN
14 Middle[MidList] <-- Mark
15 MidList <-- MidList
16 ELSE
17 Lower[HighList] <-- Mark
18 LowList <-- LowList + 1
19 ENDIF
20 ENDIF
21 MarksEntry <-- MarksEntry + 1
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 .................................................................................................................
2210 Page 18
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. [4] (Q5/22/O/N/22)
Ans.
a)
• Line 09 / Higher[HighList] <-- MarksEntry
should be Higher[HighList] <-- Mark
• Line 15 / MidList <-- MidList
should be MidList <-- MidList + 1•
• Line 17 / Lower[HighList] <-- Mark
should be Lower[LowList] <-- Mark
• Line 22 / NEXT MarksEntry = 500
Should be UNTIL MarksEntry = 500
Corrected algorithm:
01 HighList <-- 0
02 MidList <-- 0
03 LowList <-- 0
04 MarksEntry <-- 0
05 REPEAT
06 INPUT Mark
07 IF Mark >= 80
08 THEN
09 Higher[HighList] <-- Mark
10 HighList <-- HighList + 1
11 ELSE
12 IF Mark >= 50
13 THEN
14 Middle[MidList] <-- Mark
15 MidList <-- MidList + 1
16 ELSE
17 Lower[LowList] <-- Mark
18 LowList <-- LowList + 1
19 ENDIF
20 ENDIF
21 MarksEntry <-- MarksEntry + 1
22 UNTIL MarksEntry = 500
23 OUTPUT "You entered ", HighList, " higher marks"
24 OUTPUT "You entered ", MidList, " middle marks"
25 OUTPUT "You entered ", LowList, " lower marks"
b) One mark per mark point, max four
• MP1 Set up a condition to end the input
• MP2 The correct placement of the condition
• MP3 Set up the test
• MP4 The correct placement of the test
• MP5 Removal of MarksEntry counter from the original algorithm
Example answers
Testing at the end of the algorithm
OUTPUT "Do you want to enter another mark?"
INPUT AnotherMark
UNTIL AnotherMark = "No"
2210 Page 19
UNTIL AnotherMark = "No"
should replace line 22 at end of loop
The MarksEntry counter can be removed // Lines 4 and 21 are not required / can
be removed
Terminal condition
OUTPUT "Enter -1 to end the program"
should be placed before the loop and / or before the input in 06
IF MARK <> -1 THEN should be placed between lines 06 and 07
The MarksEntry counter can be removed // Lines 4 and 21 are not required / can
be removed
UNTIL Mark = -1 should be placed at line 22
2210 Page 20
Count
24 Count ← .........................................................................................................
25 UNTIL Count > 50 [6]
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] (Q2/23/O/N/22)
Ans.
a) One mark per mark point in the correct position, max six
• Line 01 50
• Line 08 Value > 50
• line 12 Reading[Value] + 1
• line 18 INPUT Value
• Line 23 Reading[Count]
• line 24 Count + 1
b) One mark per place in code and action, max three
• Line 21 set Count to 50 / Count 50
• line 24 subtract 1 from Count / Count Count –1
• line 25 check for Count equal to 34 / check for Count less than 35 / UNTIL Count =
34 / UNTIL Count < 35
or
One mark per place in code and action, max three
• line 21 set up FOR loop stating at 50 and finishing at 35 / FOR Count 50 TO 35
STEP –1
• Remove lines 22 and 24
• line 25 End FOR loop / NEXT Count
Examples
21 Count ← 50
22 REPEAT
23 OUTPUT "There are ", Reading[Count], " readings, " of ", Count
24 Count ← Count –1
25 UNTIL Count = 34
2210 Page 21
a)
2210 Page 22
IF Number >= 100 AND Number <= 200
Q. This section of program code asks for 80 numbers between 100 and 1000
inclusive to be entered. The pseudocode checks that the numbers are in the
correct range and then stores the valid numbers in an array. It counts how
many of the numbers are larger than 500 and then outputs the result when
finished.
[4] (Q6/2210/02B/SP/23)
Ans.
One mark for each error identified plus suggested correction (the corrected lines
must be written in full).
Correct lines:
Line 4 WHILE Number <= 99 OR Number >= 1001
Line 7 Num[Index] ← Number
Line 9 NEXT Index
Line 10 PRINT Count
2210 Page 23