Cambridge O Level Computer Science 2210 · 7.5 Validation and verification checks

Q30 · 2210/22/M/J/24 Q4

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 4 of 8.

Q302210/22/M/J/24original Q4Structured · 10 marks
Question 4 from 2210/22/M/J/24

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 IDEAValidation checks match one rule each: length, format and range, and SUBSTRING and LENGTH test them in pseudocode.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/22/M/J/24 question 4
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. 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.