3 Fundamental Programming
3 Fundamental Programming
1
Assignment 1 Review:
• A program is required to read from the screen the
lenght and widht of a rectangular house block, and
the lenght and width of the rectangular house that has
been built on the block. The algorithm should then
compute and display the mowing time required to cut
the grass around the house, at the rate of two square
metres per minute
Step 1
• A program is required to read from the screen the
lenght and widht of a rectangular house block, and
the lenght and width of the rectangular house that has
been built on the block. The algorithm should then
compute and display the mowing time required to cut
the grass around the house, at the rate of two square
metres per minute.
• Defining diagram
•Symbols used:
+, -, *, /, ()
Keyword used:
IF, THEN, ELSE
Keyword used:
DOWHILE, ENDDO
Statement a
Statement b
Statement c
• Add 1 to pageCount
• Print heading line 1
• Print heading line 2
• Set lineCount to zero
• Read customer record
Selection
Presentation of condition and the choice between two actions
Example:
Set student_total to zero
DOWHILE student_total < 50
Read student record
Print student name, address to report
Add 1 to student_total
ENDDO
DESIGNING A SOLUTION ALGORITHM
Number1 total
Number2
Number3
Solution Algorithm
• Add_three_numbers
Read number1, number2, number3
Total = number1 + number2 + number3
Print total
END
Example 3. 2. Find average temperature
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 3. 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