Data Validation Flashcards
All 7 cards in this deck
What is meant by a robust program?
A program that keeps working correctly, without crashing, whatever data is entered, e.g. because it validates its inputs. Robust does not mean easy to read.
What is data validation?
Checking that data entered is sensible and allowed before the program uses it, e.g. checking that a rating is in the range 1 to 10.
What does a range check do?
e.g. a height in cm must be from 40 to 180Checks the value entered lies between a stated lower and upper limit — here, that the height is at least 40 and no more than 180.
What does a presence check do?
Checks that data has actually been entered, i.e. the input is not an empty string.
What does a length check do?
Checks that the data entered has an allowed number of characters, e.g. a password of at least 8 characters.
What are the steps to write an algorithm that validates an input and re-prompts until it is valid?
e.g. a height in cm must be from 40 to 180- Input the value:
height ← STRING_TO_INT(USERINPUT) - Loop while it is outside the range:
WHILE height < 40 OR height > 180 - Inside the loop, output an error message and input the value again; the loop (
ENDWHILE) ends when the value is valid.
- Input the value:
True or false?
IF height ≥ 40 AND ≤ 180 THENis a correct range check.False. The variable must be repeated in each comparison:
IF height ≥ 40 AND height ≤ 180 THEN.