Desk Checking Algorithms
Desk Checking Algorithms
Algorithms
The basic idea of desk checking is that you step through the algorithm step by step
and document each variable and how it changes as it goes through the algorithm.
1 BEGIN displayGrade()
2 Input mark
3 IF mark >= 50 THEN
4 grade = "Pass"
5 Display "Well done"
6 ELSE
7 grade = "Not pass"
8 ENDIF
9 Display grade
10 END
There is also, obviously, an output in any program. You input variables and output
results in any program.
You also want to test a certain number of sets of data for the program. In an exam,
they will normally tell you what data to test.
Line 6 and 7.
6 ELSE
7 grade = "Not pass"
Line 9
9 Display grade
Number of Trains
Train
Train ID
Location X
Location Y
X
Y
Now, a table…
The question gave you the set of values for number of trains as 0, 1 and 2..so…for 0
Set Number Train TrainID Location Location X Y Output
of X Y
Trains
1 0 1 Train001 Location Location “Train
X Y 001 at
X, Y”
2 Train002 Location Location “Train
X Y 002 at
X, Y”
3 Train003 Location Location “Train
X Y 003 at
X, Y”
Never ending loop due to Number of Trains never equalling Train Number
Train doesn’t equal number of trains (0 doesn’t equal 1, so the loop is entered)
ReadTrainID(TrainID)…there’s no sub procedure listed for
ReadTrainID(TrainID). You can assume that it’s just inputting the trainID. As
we’re not given this value to test, we can either make it up, or just put in
trainID.
ReadLocation (TrainID,LocationX,LocationY) is giving us the train and, it’s
X and Y co-ordinates (location)
As you don’t know what the next two subprocedures do, you can ignore them
and pass over them. A good desk check should include them, however, you’re
not given enough info in this question to do it.
Ok, you’re going back to line 7 in the algorithm, because you’ve finished that
sub procedure.
DisplayTrainID(TrainID, LocationX, LocationY) takes you to line 17. So, the
output is “Train ID at X, Y”
You then go back to line 8, train = train + 1, so train now equals 2
Go through all that again because Train<>Number of trains yet.
As you go through this, you notice that you keep going up in train Numbers,
but not Number of Trains, so you see that the loop will never end.
Continuing the rest of the desk check: