Premise:
The problem above is simple enough for anyone. The solution here will give you a clue on how to tell computer to follow such steps.As you it might be going on on mind now, we will need two variables x and y say, to hold the two numbers. Another two variables to hold their product and difference.
So if you are confidence enough, go forth before me to solve the problem when you have finished, compare yours with mine. Note our steps must not be same. In other words our algorithm must be different, if their are not then perhaps you cheated!
Solution:
Major Steps
1. Request Data
2. Calculate Data
3. Display Product, Difference
Stepwise Refinement
1. Request Data
1.1 Request x
1.2 Request y
2. Calculate Data
2.1 Product = x * y
2.2 Difference = x - y
3. Display Product, Difference
1. Request Data
2. Calculate Data
3. Display Product, Difference
Stepwise Refinement
1. Request Data
1.1 Request x
1.2 Request y
2. Calculate Data
2.1 Product = x * y
2.2 Difference = x - y
3. Display Product, Difference
Explanation:
The step 2.1 and 2.1 above calculate the product and difference of the numbers x and y. When developing your algorithm I know you faced the problem of what number that should be subtracted from the other, since x – y give a different result compare to y - x. Here you have to use convection, though in the question we are not told which to subtract from.So, I subtract the first number from the second and that should be the right thing to do until you encounter a problem that will give the order of the arithmetic.
Do this one yourself:
If the algorithm (question) requires that we sum the product and the difference of the two numbers, make a change from step 2 to show this new requirement. When you have finished make use of the comment box for your answer.
Hint: check example ten.
SHARE THIS POST WITH YOUR FRIENDS...::
Tweet
0 comments:
Leave a Reply