Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.
Loop through the ten elements of IgnoreList, compare in the same case, set a flag when found, then return it:
FUNCTION IgnoreWord(ThisWord : STRING) RETURNS BOOLEAN
DECLARE Found : BOOLEAN
DECLARE Index : INTEGER
Found ← FALSE
Index ← 1
ThisWord ← TO_LOWER(ThisWord)
REPEAT
IF TO_LOWER(IgnoreList[Index]) = ThisWord THEN
Found ← TRUE
ENDIF
Index ← Index + 1
UNTIL Found = TRUE OR Index > 10
RETURN Found
ENDFUNCTIONLoop through the elements of IgnoreList [1]
Both strings converted to the same case before comparing [1]
Each array element compared with the parameter inside the loop [1]
A flag set when a match is found, inside the loop [1]
TRUE or FALSE returned in every case [1]
Only 4 marks can be scored if the function heading is wrong.
Count the words one at a time. GetStart() gives -1 when there is no such word. For each word that exists and is not ignored, add its first letter in upper case:
PROCEDURE GetInitials()
DECLARE NewString, NextWord : STRING
DECLARE ThisWordNum, Index : INTEGER
ThisWordNum ← 0
NewString ← ""
REPEAT
ThisWordNum ← ThisWordNum + 1
Index ← GetStart(ThisWordNum)
IF Index <> -1 THEN
NextWord ← GetWord(Index)
IF IgnoreWord(NextWord) = FALSE THEN
NewString ← NewString & UCASE(LEFT(NextWord, 1))
ENDIF
ENDIF
UNTIL Index = -1
OUTPUT NewString
ENDPROCEDURENewString declared and set to the empty string [1]
Conditional loop that picks out all the words in FNString [1]
Result of GetStart() stored and checked inside the loop [1]
Tests that the result is not -1 before using it [1]
Result of GetWord() assigned to a variable inside the loop [1]
Result of IgnoreWord() tested inside the loop [1]
If the word is not ignored, its first letter is added to NewString [1]
NewString output after the loop, all in upper case [1]
Other points that also score: the word number increased inside the loop (it was set to 0 before the loop).
▶ Whole paper
Video solution of the whole paper · by Papersdock. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.