2210/21/M/J/25 question 4: worked solution (May/June 2025, paper 21)
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. Q110 2210/21/M/J/25 original Q4 Structured · 8 marks Worked solution (a) Plan: input the number, take 2 characters starting at position 2 (after the '+'), then compare them with the two country codes. One correct answer: OUTPUT "Please enter a telephone number" INPUT Telephone Code ← SUBSTRING(Telephone, 2, 2) IF Code = "44" THEN OUTPUT "UK" ELSE IF Code = "20" THEN OUTPUT "Egypt" ELSE OUTPUT "Unknown" ENDIF ENDIF Telephone number input correctly [1] Use of SUBSTRING (or similar) to take the code [1] ... with the correct start and length, so the 2 digits after the '+' are extracted [1] IF (or CASE ) used to check the code, with matching ENDIF / ENDCASE [1] Matching country output for 44 and 20, and Unknown output otherwise [1] Other correct ways also score, for example a CASE OF statement or two separate IF statements. (b) Write that you need a loop that keeps asking until the length is right: Find the length of the number entered, using LENGTH(Telephone) [1] Use a suitable loop , for example REPEAT ... UNTIL or WHILE ... ENDWHILE, with the prompt and INPUT inside it [1] Use the correct condition : the loop stops when LENGTH(Telephone) = 13 (a WHILE loop repeats while it is not 13) [1] KEY IDEA Use SUBSTRING to pull out part of a string, and put a prompt inside a loop with a length test to force valid input. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.