Beruflich Dokumente
Kultur Dokumente
Introduction
Learning outcomes
• On completing this lesson, you would be able to :
o Explain the use of different programme design approaches
o Apply design techniques.
Usually, solutions to small problems can be easily described, but many problems
we need to solve with the use of a computer will appear to be very large and
complex. In fact, many of the problems are large and complex. It is up to us to
find solutions to these large, complex problems.
We can use many different tools and methodologies to achieve this. They are
centered on breaking down the problem into more manageable parts.
In this approach, we try to break down the problem into components. Each of
these components is then broken down into smaller components, and this
process is continued until components that can be easily solved are reached
through algorithms and implemented in some programming language. However,
To organize a batch
party
Now let us identify different sub problems of this problem:
To organize a batch
party
This process will go on until we have things that we can easily do, such as
preparing the invitee list. On the other hand, you may have to break some of
these sub-problems into much smaller tasks. For example, print and mail letters
may be broken down into tasks such as drafting the letter, typing the letter,
proof reading the letter, preparing the invitee database, mail merging and
posting.
While Top down design provides us with a hierarchy chart that shows the inter-
relationship between different parts of the solution, we need some mechanism
to describe the solution. A process closely associated with top-down design is
known as step-wise refinement. In step-wise refinement, we keep on refining
the solution in each step until we reach a solution that can be easily
implemented in a programming language.
3.2.1 Flowcharts
Routine
1 continued later
Decision
(in another
diagram)
End of a Sub
END End of a routine EXIT
program
START
Read
number1,
number2
Print Result
END
Figure 3.2 - Flowchart of adding two numbers and displaying the value
Activity 3.1
1. Draw a flow chart to calculate the interest earned by investing a certain sum at a bank at
a given interest rate.
2. Draw a flow chart to calculate the sum and the average of three numbers.
3. Draw a flow chart to read student’s name and marks for five subjects and display the
average mark.
Begin
Read investment, interest_Rate
interest_Earned = investment * interest_Rate
Print "Interest Earned", interest_Earned
End
Example 3: Modify the algorithm in Example 2 to print the value of the
investments at the end of each year for 10 years, if the interest is
reinvested in the bank.
Begin
Read investment, interestRate, numberOfYears
For counter = 1 to numberOfYears increment 1
interestEarned = investment * interestRate
investment = investment + interestEarned
Print "Total Investment at the end of year",
These are only some simple algorithms. More complicated programmes would
use selection statements and iterative statements as well. When programmes
are too large, sub-programme statements can be used to decompose them into
more manageable chunks. Each sub-programme can be designed separately and
checked for correctness and then combined together to form a single solution.
Since the final use of any algorithm is to write a computer programme that can
be executed, we will now translate some of the algorithms that we have written
into java.
Now one known how to design a programme and code it using pseudo code.
Actually pseudo code is an algorithm we are writing to accomplish a task. So it
should be a finite set of well defined instructions that would take the input to
the problem and produce the desired output (Figure 3.3).
Summary
This section discussed how to design a computer programme, using a top-down
design. We also discussed about programme design techniques, such as
flowcharts and pseudo-codes. Finally we examined certain important
characteristics algorithms should have. This lesson is the last lesson in this
week.
In the next week’s sessions, we will discuss how to define data types and how
to declare variables.