Professional Documents
Culture Documents
Developing an algorithm
• To help the initial analysis, the
problem should be divided into 3
separate components:
1. Input: a list of the source data provided to
the problem
2. Output: a list of the outputs required
3. Processing: a list of actions needed to
produce the required outputs.
Example 1. Add three numbers
Number1 total
Number2
Number3
2. Underline the verbs and adverbs used in
the specification establish the action
required.
Total 60 123
3. Set up a table of relevant variable names, and pass
each test data set statement by statement.
Statement number1 number2 number3 total
number
First Pass
1 10 20 30
2 60
3 Print
Second
Pass
1 40 41 42
2 123
3 Print
4. Check the expected results (60 and 123) match the
actual results.
Desk Check of Example 2.
• A program is required to prompt the terminal operator
for the maximum and minimum temperature readings
on a particular day, accept those readings as integers,
and calculate and display to the screen the average
temperature, calculated by (maximum temperature +
minimum temperature)/2.
Solution Algorithm
• Find average_temperature
Prompt operator for max_temp, min_temp
Get max_temp, min_temp
Avg_temp= (max_Temp + min_temp)/2
Output avg_temp to the screen
END
Desk Checking
1. Choose two sets input test data.
Set 1: 30, 10 and Set 2: 40, 20
Avg_temp 20 30
3. Set up a table of relevant variable names, and pass
each test data set statement by statement.
Statement Max_temp Min_temp Avg_temp
number
First Pass
1,2 30 10
3 20
4 0utput
Second Pass
1,2 40 20
3 30
4 output
4. Check the expected results match the actual results.
Assignment 2:
Desk Checking for
Compute mowing time
Calculate_mowing_time
Prompt operator for block_lenght, block_width
Get block_length, block_width
block_area = block_lenght * block_width
Prompt operator for house_lenght, house_width
Get house_lenght, house_width
house_area=block_lenght * block_width
Mowing_area=block_area - house_area
Mowing_time=mowing_area/2
Output mowing_time to screen
END
Assignment 2 Review:
Calculate_mowing_time
1 Prompt operator for block_lenght, block_width
2 Get block_length, block_width
3 block_area = block_lenght*block_width
4 Prompt operator for house_lenght, house_width
5 Get house_lenght, house_width
6 house_area=house_lenght*house_width
7 Mowing_area=block_area-house_area
8 Mowing_time=mowing_area/2
9 Output mowing_time to screen
END
Desk Checking
1. Input data:
First Pass
1,2 30 30
3 900
4,5 20 20
6 400
7 500
8 250
9 Output
Second Pass
1,2 40 20
3 800
4,5 20 10
6 200
7 600
8 300
9 Output
4. Check the expected results match the actual results.