KEMBAR78
Desk Check Example - Modules | PDF | Applied Mathematics | Theoretical Computer Science
0% found this document useful (0 votes)
177 views2 pages

Desk Check Example - Modules

This document describes a desk check of a program that finds the smallest of three numbers using a sub-algorithm called getSmallestNumber(). The sub-algorithm takes the three numbers as inputs, sets the smallest number to the first input, and then checks if the other two inputs are smaller, updating smallest if they are. It then returns smallest. The main algorithm calls getSmallestNumber(), assigns the return value to smallest, and displays it. The desk check walks through two examples to verify the program works correctly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views2 pages

Desk Check Example - Modules

This document describes a desk check of a program that finds the smallest of three numbers using a sub-algorithm called getSmallestNumber(). The sub-algorithm takes the three numbers as inputs, sets the smallest number to the first input, and then checks if the other two inputs are smaller, updating smallest if they are. It then returns smallest. The main algorithm calls getSmallestNumber(), assigns the return value to smallest, and displays it. The desk check walks through two examples to verify the program works correctly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Desk Check Example 9 – Module (Sub-algorithm)

The following example shows desk checking involving a sub-algorithm aka module.

When a sub-algorithm is called, processing goes from the calling line (module call e.g. line 3 in
this example) to the first line in the sub-algorithm (e.g. line 6). The sub-algorithm is then
executed, and when the end of the sub-algorithm is reached (e.g. line 14), execution goes back to
the line after where it was originally called (e.g. line 4).

Problem Description: Find the smallest of 3 numbers.

Pseudocode (with line numbers added for the Desk Check)

6 Function getSmallestNumber(tnumber1, tnumber2, tnumber3)


7 tsmallest = tnumber1
8 IF tnumber2 < tsmallest THEN
9 tsmallest = tnumber2
10 ENDIF
11 IF tnumber3 < tsmallest THEN
12 tsmallest = tnumber3
13 ENDIF
14 Return(tsmallest)

1 Algorithm compareNumbers()
2 Input number1, number2, number3
3 smallest= getSmallestNumber(number1, number2, number3)
4 Display smallest
5 Halt

Desk Check

Inputs: number1 = 5, number2 = 3, number3 = 8.


Expected correct result: smallest = 3.

Pseudocode number1 number2 number3 smallest Conditions Input/ Output


Line Number
1
2 5 3 8 number1 ? 5;
number2 ? 3;
number3 ? 8
3
6
7 5
8 3 < 5 ? is T
9 3
10
11 8 < 3 ? is F

1
13
14
3 3
4 smallest = 3
5

Inputs: number1 = 7, number2 = 12, number3 = 9.


Expected correct result: smallest = 7.

Pseudocode number1 number2 number3 smallest Conditions Input/ Output


Line Number
1
2 7 12 9 number1 ? 7;
number2 ? 12;
number3 ? 9
3
6
7 7
8 12 < 7 ? is F
10
11 9 < 7 ? is F
13
14
3 7
4 smallest = 7
5

You might also like