![]() |
Example 4A gardener requires a program which will calculate the length of fencing needed for a rectangular garden, given that she knows the length and width. 1. Design a Solution Using a similar approach to the last example, we'll start with the following: 1. get information from user
As before, we take each of these steps in turn and write down in more detail what each one does. What information do we need? How do we calculate the length of fencing? Step 1 becomes: 1.1 ask user to enter length of garden
Step 2 becomes: 2.1 total length of fencing is 2 x length + 2 x width Step 3 becomes: 3.1 print the length
The complete design is shown below.
|
1.1 ask user to enter length of garden
2.1 total length of fencing is 2 x length + 2 x width 3.1 print the length
|
The program needs to use three numbers - the length and width of the garden and the total length of fencing. What type of numbers should they be - whole numbers or decimal numbers?
|
identifier | type |
length | |
width | |
total |
3. Testing the Program When you've got the program running, you need to test it.
4. Evaluation Have a look at the evaluation for the last example and use it as a guide for this one.
|