Algorithm Design and Problem Solving · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 6% of your exam marks.
Decomposition, abstraction and structure charts appear as design-focused questions.
Validation is an automated check carried out by the program that an input is plausible and obeys the rules of the field it belongs to, applied the moment the data is entered.
Validation cannot guarantee that an input is correct (no program can tell whether a typed name is really the user's name). It can only guarantee that the input is plausible. A well-validated form accepts everything that is plausible and rejects everything that is obviously wrong.
The syllabus names six validation checks you should know.
Tests that a number falls within a specified range.
Example — A program accepts ages from 0 to 110 only.
Pseudocode:
INPUT age
WHILE age < 0 OR age > 110 DO
OUTPUT "Age must be between 0 and 110"
INPUT age
ENDWHILE
Tests that a string has the right number of characters.
Example — A bank PIN must be exactly 4 digits.
INPUT pin
WHILE LENGTH(pin) <> 4 DO
OUTPUT "PIN must be 4 characters"
INPUT pin
ENDWHILE
Tests that the input is of the expected data type (integer, real, string, boolean, etc.).
Example — A program asks for an age and rejects anything that is not a whole number.
Tests that a value has actually been entered (the field is not blank).
Example — A registration form requires both a username and a password to be filled in before submitting.
Tests that the input matches a specific pattern.
Example — An employee ID must be two uppercase letters followed by four digits, e.g. AB1234.
A format check uses pattern matching or string handling to verify each part of the string is what it should be.
An extra digit appended to a numerical code (e.g. ISBN, barcode) that is calculated from the other digits and used to verify that the code was entered correctly.
Check digits were covered in detail in topic 5 (Error Detection); the same idea is reused as a validation method on input forms.
A single field may need several validation checks at once. A password field might use a length check (at least 8 characters), a presence check (not blank), and a format check (must contain a letter and a digit). Each check rules out one kind of invalid input.