Desk Checking Algorithms

  • Uploaded by: Kelly Bauer
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Desk Checking Algorithms as PDF for free.

More details

  • Words: 744
  • Pages: 4
Desk Checking 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. Lets take an example algorithm: 1 2 3 4 5 6 7 8 9

BEGIN displayGrade() Input mark IF mark >= 50 THEN grade = "Pass" Display "Well done" ELSE grade = "Not pass" ENDIF Display grade

10 END

Step 1: List the variables Okay, first thing you do is list all the variables in the program. In this case, that is only mark and grade. 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.

Step 2: Create the table Set

Mark

Grade

Output

Step 3: The desk check Now, you have to manually step through each line of the algorithm and record what happens (unless nothing happens). Our first set of data is going to be Mark=34 Set 1

Mark 34

Grade

So, stepping through the algorithm… Line 1 does nothing. Line 2, inputs mark

Output

Line 3, IF mark >= 50 THEN Ok, so in your test data, is mark >=50? No, then skip lines 4 and 5 to the else statement. Line 6 and 7. 6 7

ELSE grade = "Not pass"

This is a change of variable, so you have to record it on your deskcheck Set 1 Line 9 9

Mark 34

Grade Not Pass

Output

Display grade

is your output, so place it in the output column Set 1

Mark 34

Grade Not Pass

So, if you have multiple sets of data: Set Mark Grade 1 34 Not Pass 2 50 Pass 3

65

Pass

So what about more complex algorithms?

Output Not Pass

Output Not Pass Well done Pass Well Done Pass

Firstly, go through and list all the variables. Number of Trains Train Train ID Location X Location Y X Y Now, a table… Set Number Train TrainID Location X of Trains

Location Y

X

Y

Output

The question gave you the set of values for number of trains as 0, 1 and 2..so…for 0 Y Output Set Number Train TrainID Location Location X X Y of 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: Number Train of Trains 0 1 2 3

1

1

2

1 2

TrainID

X

Y

Output

Train 001 Train 002 Train 003

LocationX

LocationY

Train 001 is at Location X, Location Y

LocationX

LocationY

Train 002 is at Location X, Location Y

LocationX

LocationY

Train 003 is at Location X, Location Y

LocationY

Endless loop due to value of Train never = Niumber of Trains Terminates without looping due to value of train = number of trains initially Train 001 is at Location X, Location Y

Train 001

LocationX

Terminates as Train=Number of trains

Related Documents

Desk Checking
October 2019 19
Checking
November 2019 23
Desk
June 2020 22
Desk
December 2019 27
Desk
June 2020 24

More Documents from ""