Validation and verification
- Validation is appropriate to check that only reasonable data is accepted when
data is entered.
- Validation is an automated check carried out by a computer to make sure the data
entered is reasonable
- abnormal data – test data chosen to be rejected by the solution as not
suitable, if the solution is working properly
- extreme data – the largest and smallest values that normal data can take
- Normal data - the data lies within the required range and is accepted
- Verification is appropriate to check that the data does not change as it is being
entered.
- Verification is used to ensure that data has been accurately copied from one
source to another
- Visual check
- Use – the user looks through the data that has been entered and confirms that
no changes
- Double data entry
- Use – data is entered twice, the two entries are compared and if they do not
match, a re-entry is requested
Definitions of data types
- integer: a positive or negative whole number that can be used with mathematical
operators
- real: a positive or negative number with a fractional part that can be used with
mathematical operators
- Boolean: a variable or constant that can have only two values TRUE or FALSE
- char: a single alphanumeric character
- string: multiple alphanumeric characters
Difference between variables constants
- variables and constants are used to store items of data
- the data stored in variables and constants are accessed by an identifier
- the value of a variable may change during the execution of a program
- the value of a constant will remain the same during the execution of a program
Difference between calling and defining a function
A function is defined once and called many times
Defining a function is setting up the function and calling a function is using a
function
Functions and their use
DIV
- To perform integer division
- Meaning only the whole number part of the answer is retained
- For example, DIV(9,4) = 2
ROUND
- To return a value rounded to a specified number of decimal places
- The result will either be rounded to the next highest or the next lowest
value
- depending on whether the value of the preceding digit is >=5 or <5
- for example, ROUND(4.56, 1) = 4.6
MOD
- To perform integer division when one number is divided by another
- ... and find the remainder
- For example, 7 MOD 2 = 1
RANDOM
- To generate (pseudo) random numbers
- …. within a specified range
- for example, RANDOM() * 10 returns a random number between 0 and 10
Features of high level languages that can be used to make a program easier to
understand
- Meaningful identifiers – to enable the programmer to easily recognise the purpose
of a variable, array, or constant through the program
- Use of comments – to annotate each section of a program so that the programmer
knows the purpose of that section of code
- Procedures and functions – to make programs modular and easier to update
How to make a program easier to understant
- ensuring that all identifiers have meaningful names. For example, using Total to
store a running total
- using comments to explain how the program works. For example, // all values are
zeroed before the next calculation
- using procedures and functions for the tasks within a program. For example,
CalculateInterest(Deposit, Rate)
What happens when a function is called
- the function is called using its identifier
- Parameters are passed (from the main program) to the function (to be used
within the function)
- The function performs its task ...
- ... and returns a value to the main program
Advantages of storing data in files
- data is stored permanently
- data can be moved to another computer
- another copy of data can be made and stored
Difference between local and global variables
- local variables - scope is a defined subroutine
- global variables – scope is the whole program
- local variables - value cannot be changed elsewhere in the program
- global variables – value can be changed anywhere in the program