Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q12 · 9618/22/M/J/21 Q8

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.

Q129618/22/M/J/21original Q8Structured · 13 marks
Question 8 from 9618/22/M/J/21

Worked solution

(a)

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
ENDFUNCTION

Loop 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.

(b)

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
ENDPROCEDURE

NewString 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).

KEY IDEACall the helper modules in a loop that ends when GetStart() returns -1, and build the result string from the words that are not ignored.
TOTAL 13 marks

Official mark scheme

Mark scheme for 9618/22/M/J/21 question 8
VIDEO
▶ 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.