Producing robust programs Flashcards
Define what is meant by validation [1]
validation is the process of checking that any data that is input is sensible, reasonable, and appropriate
State what is meant by a presence check [1]
a presence check ensures that some data has been input
State what is meant by a range check [1]
a range check ensures that the data entered falls within a certain range of values
Write an algorithm, using pseudocode, that allows a user to enter the month and day of their birth as a number. Your algorithm should have routines to validate each entry. [8]
validMonth = False
while validMonth == False
month = input(“Please enter the month of your birth as
a number.”)
if month < 1 OR month > 12 then print("This is not a valid month.") else validMonth = True endif endwhile
validDay = False
while validDay = False
day = input(“Please enter the day of your birth.”)
if month == 2 AND day > 29 then
print(“This is not a valid day.”)
The following statement is part of a program for entering student data into a school system:
if yearGroup < 7 OR yearGroup > 13 then
print(“Incorrect entry.”)
endif
Suggest data that could be used for the following test.
a) boundary data
b) erroneous data
a) 7 or 13
b) 100 (or another invalid number)
Explain the difference between a syntax error and logic error [2]
syntax errors are grammatical mistakes in code, which could be caused by a misspelling (e.g. prnit instead of print)
logic errors are fundamental mistakes in the underlying way in which the algorithm is constructed, which often cause unforeseen ouput
(e.g. creating an infinite loop)
Describe two techniques that computer scientists use to make their programs easier to read, understand and maintain [4]
computer scientists explain the logic of their coed using comments
programming languages have special symbols (e.g. //) that designate that a line of text is a comment and not code to be executed
indentation is also used to show where statements depend on ones used above (e.g. all the code to be executed by an if statement is indented)