2210/21/M/J/25 question 9: worked solution (May/June 2025, paper 21)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 8.1 Programming concepts Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3. Q36 2210/21/M/J/25 original Q9 Structured · 8 marks Worked solution (a) Declare each variable with its data type. A holds a whole number and B holds text: DECLARE A : INTEGER DECLARE B : STRING DECLARE A : INTEGER [1] DECLARE B : STRING [1] (b) Define the function first. It needs a parameter X and it returns text. Use MOD to test for odd or even: an even number has remainder 0 when divided by 2. FUNCTION Odds(X : INTEGER) RETURNS STRING IF MOD(X, 2) = 0 THEN RETURN "Even" ELSE RETURN "Odd" ENDIF ENDFUNCTION B ← Odds(A) Uses FUNCTION , ENDFUNCTION and RETURNS STRING [1] Function is named Odds [1] Parameter defined correctly, for example X : INTEGER [1] Odd or even tested using MOD (or DIV or ROUND) on the parameter [1] Returns "Odd" and "Even" correctly [1] Function call stores the result in B: B ← Odds(A) [1] KEY IDEA A function is defined with FUNCTION, a parameter and RETURNS, and it is called by putting the call on the right of an assignment. 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.