Note that your final mark will not be saved in the system.
Robust and Secure Programming GapFill
You must fill all the gaps before clicking ‘Check Answers!’
It can be hard to predict every input that a program will need to process, especially when user input is required. When designing a program, it is important to think about all the possible data inputs that your program must be able to handle to ensure that your program is robust and will not crash. Data techniques must be included in your program to check the of data entered by a user.
There are a number of ways to create simple validation checks, look at these examples:
PRINT('Enter a number between 1 and 20') num ← USERINPUT IF num >= 1 AND num <= 20 THEN valid ← True ELSE valid ← False ENDIF |
valid ← PRINT('Enter your name') WHILE not valid name ← USERINPUT IF LEN(name)<= 1 THEN PRINT('You have not entered any text') PRINT('Enter your name') ELSE valid ← True ENDIF ENDWHILE |
The first example is not user-friendly as it gives the end user no information about the validity of their data entry, the second version is an improvement because it gives feedback to the user but this version could continue to loop if the user never enters more than one character. This could be improved by limiting the of attempts before the program exits.
These checks only ensure that data entered is , they do not check the data entry is correct. is the process of checking that a user is who they claim to be, for example if you want to shop online at a store you will need to create an account with a username and which are initially checked through email confirmation and double entry of a password.
In this example the authentication process is limited to three attempts:
PRINT('Enter password: ')
password ← USERINPUT
PRINT('Confirm password :')
confirm ← USERINPUT
count ← 3
valid ← False
WHILE count > 0 valid = False
IF confirm != password THEN
PRINT('Entry does not match')
ELSE
PRINT('Password accepted')
valid ←
ENDIF
PRINT('Confirm password :')
confirm ← USERINPUT
count ← count - 1
ENDWHILE
As well as handling any errors that may be introduced by user input, you should also be aware of errors that may be introduced when developing a program. There are two general types of error that can be made: errors, that occur when the programming language doesn't recognise a command which it has been given, causing the program to fail to be translated into machine code; and errors, which are accepted as valid code, but cause the program to do something that the programmer did not intend.
In all cases detailed testing of programs using normal, and extreme data should enable the programmer to identify and correct all errors.