2210/22/O/N/25 question 4: worked solution (October/November 2025, paper 22)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8. Q113 2210/22/O/N/25 original Q4 Structured · 7 marks Worked solution (a) Write: to check that the data entered has the required number of characters (the right length). [1] (b) Start at the first character. Look at one character at a time with SUBSTRING. Stop when an @ is found or the end is reached. Then output a message. INPUT EmailAddress Start ← 1 Valid ← FALSE REPEAT IF SUBSTRING(EmailAddress, Start, 1) = '@' THEN Valid ← TRUE ELSE Start ← Start + 1 ENDIF UNTIL Start > LENGTH(EmailAddress) OR Valid = TRUE IF Valid = TRUE THEN OUTPUT EmailAddress, " is valid" ELSE OUTPUT EmailAddress, " is NOT valid" ENDIF Start position and the flag set before the loop (Start ← 1, Valid ← FALSE) [1] Email address input into a variable [1] A condition-controlled loop (REPEAT or WHILE) that stops when @ is found or no characters are left [1] SUBSTRING used correctly to pick out one character, which is compared with '@' [1] If '@' is found the loop ends (flag set to TRUE); if not, move to the next character [1] Output that shows a message for valid and a message for not valid (both cases) [1] Other correct loops, flags or ways of stopping the loop also score. KEY IDEA Check each character in turn with SUBSTRING in a condition-controlled loop, stop when you find the symbol, then output a message for both outcomes. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by MAK CS. Tap the picture to open it on YouTube.