This lecture focuses on step 5 of the Steps in Program Development - Desk Checking
A desk check is a manual (non computerised) technique for checking the logic of an algorithm. The person performing the desk check effectively acts as the computer, using pen and paper to record results. The desk checker carefully follows the algorithm being careful to rigidly adhere to the logic specified. The desk check can expose problems with the algorithm.
Desk checks are useful to check an algorithm (before coding) thereby confirming that the algorithm works as expected. This can save time as the programmer doesn't waste time writing a program that doesn't do what is intended.
A desk check is done as a table, with columns in the order shown below:
Pseudo Code (with line numbers shown)
1 addTwoNumbers() 2 Input number1, number2 3 total = number1 + number2 4 Display total 5 STOP
Test data: number1 = 10, number2 = 3, total = 13
| Line Number | number1 | number2 | total | Input/Output |
| 1 | ||||
| 2 | 10 | 3 | Number 1 ? 10 Number 2 ? 3 |
|
| 3 | 10 + 3 =13 | |||
| 4 | total = 13 | |||
| 5 |
A more compact version of the above is normally used and is shown below. As line 1 doesn't perform any action (it would be a blank row in the desk check), it is combined with next line of code to be executed and shown in a single row in the desk check.
| Line Number | number1 | number2 | total | Input/Output |
| 1, 2 | 10 | 3 | Number 1 ? 10 Number 2 ? 3 |
|
| 3 | 10 + 3 =13 | |||
| 4 | total = 13 | |||
| 5 |
It is important to have a go at problems. Attempting and solving problems is essential in learning to program. With time you will begin to develop a knowledge base of problem types to draw on. These can be used to help solve problems.
Don't expect to get it right the first time. Look at your solution - does it do what is required? A Desk Check is a useful tool for checking that the algorithm performs as required. Modify your solution as necessary. Learn from your successes and your mistakes.
Write a program that allows a user to input their name, then displays Hello student-name.
Run Name ? Jane Hello Jane
Run Name ? Peter Smith Hello Peter Smith
name = "Jane"
Display "Hello Jane"
| Inputs | Processing | Output |
| name | Input name Display name |
name |
This is a simple problem and requires no more detail.
hello()
Input name
Display "Hello ", name
STOP
Data Dictionary
| Name | Data Type | Description |
| name | String | The name of a person |
1 hello() 2 Input name 3 Display "Hello ", name 4 STOP
Inputs: name = Jane;
Correct results: Hello Jane
| Line Number | name | Input/Output |
| 1, 2 | Jane | Name ? Jane |
| 3 | Hello Jane | |
| 4 |
Inputs: name = Peter Smith;
Correct results: Hello Peter Smith
| Line Number | name | Input/Output |
| 1, 2 | Peter Smith | Name ? Peter Smith |
| 3 | Hello Peter Smith | |
| 4 |
A program is required to display the square and cube of a number input by a user..
Example Runs
Run x ? 2 x squared = 4 x cubed = 8
Run x ? 5 x squared = 25 x cubed = 125
| Inputs | Processing | Outputs |
| |
Data Dictionary
| Name | Data Type | Description |
Inputs: x = 2;
Correct results: xSquared = 4, xCubed = 8
| Line Number | x | xCubed | xSquared | Input/Output |
Inputs: x = 5;
Correct results: xSquared = 25, xCubed = 125
| Line Number | x | xCubed | xSquared | Input/Output |
It can be difficult to compare the price of items in a supermarket when the items are different sizes. In some countries, supermarkets display a price per 100 grams for items to make comparisons easier. For example, which is the better value, 250g of honey at a cost of $5.00, or 500g for $8.00, or 375g for $5.95? Write a program to allow the user to input the weight in grams and the cost of an item, and display the cost per 100g. Hint: the weight needs to be converted to lots of 100g (e.g. divide the weight in grams by 100).
Example Runs
Run Weight (g) ? 250 Cost ($) ? 5.00 Cost per 100g = $2.00
Run Weight (g) ? 500 Cost ($) ? 8.00 Cost per 100g = $1.60
weight = 250, cost = $5.00.
weight in lots of 100 grams = 250 / 100 = 2.5.
cost per 100g = cost / weight in lots of 100 grams = 5.0 / 2.5 = $2.00
weight = 500, cost = $8.00:
weight in lots of 100 grams = 500 / 100 = 5.0.
cost per 100g = cost / weight in lots of 100 grams = 8.00 / 5.0 = $1.60
| Inputs | Processing | Outputs |
| weight cost |
Input weight, cost Calculate weightInLotsOf100Grams Calculate costPer100Grams Display costPer100Grams |
costPer100Grams |
This is a simple problem and requires no more detail.
Data Dictionary
| Name | Data Type | Description |
| cost | Double | The cost of the item in $. |
| costPer100Grams | Double | The cost in $ of 100 grams of the item. |
| weight | Integer | The weight of the item in whole grams. |
| weightInLotsOf100Grams | Double | The weight of the item in 100 grams lots. e.g. an item weighing 325grams is 3.25 x 100g |
Inputs: weight = 250, cost = 5
Correct results: costPer100Grams = 2.0
| Line Number | cost | costPer100Grams | weight | weightInLotsOf100Grams | Input/Output |
Inputs: weight = 500, cost = 8
Correct results: costPer100Grams = 1.6
| Line Number | cost | costPer100Grams | weight | weightInLotsOf100Grams | Input/Output |
In the next lecture we will look at converting an algorithm into a program and introduce programming in Visual Basic.
Written by Tim Whitfort.