2210/22/M/J/24 question 4: worked solution (May/June 2024, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 7.5 Validation and verification checks Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 4 of 8. Q30 2210/22/M/J/24 original Q4 Structured · 10 marks Worked solution (a) Pick one check for each rule. Write the check name and what it does. Length check [1] It makes sure the product code entered is 6 characters long. [1] Format check [1] It makes sure the first two characters of the product code are "PD" . [1] Range check [1] It makes sure the number made by the last four characters is between 1000 and 9999 . [1] (b)(i) Use the LENGTH function and keep asking for input until the length is 6. REPEAT INPUT Product UNTIL LENGTH(Product) = 6 Correct use of LENGTH on Product [1] Correct test that the result equals 6, so the loop stops only for a valid code [1] Other correct loops (for example WHILE with an error message) also score. (b)(ii) Use SUBSTRING to take the first two characters, starting at position 1, and compare them with "PD". REPEAT INPUT Product UNTIL SUBSTRING(Product, 1, 2) = "PD" Correct use of SUBSTRING (start 1, length 2) [1] Correct test that it equals "PD" [1] KEY IDEA Validation checks match one rule each: length, format and range, and SUBSTRING and LENGTH test them in pseudocode. TOTAL 10 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.