New Microsoft PowerPoint Presentation (2)
New Microsoft PowerPoint Presentation (2)
DESIGNING AND
PROBLEM
SOLVING
7.1 THE DEVELOPMENT
LIFE CYCLE
• The program
development life
cycle is divided into
five stages: analysis,
design, coding,
testing.
Abstraction keeps the key elements required for the solution to the problem and discards any unnecessary
details and information that is not required. For example, a map only shows what is required for travelling
from one place to another. Different methods of transport will require different types of map.
Decomposition breaks down a complex problem into smaller parts, which can then be subdivided into even
smaller parts, that can be solved easily. Any daily task can be divided into its constituent parts.
7.1.2 Design
The program specification
from the analysis stage is
used to show to how the
program should be
developed. When the
design stage is complete,
the programmer should
know what is to be done, all
the tasks that need to be
completed, how each task is
to be performed and how
the tasks work together. This
can be formally documented
using structure charts,
flowcharts and
pseudocode – see Section
Pseudocode Flowchart 7.2.
7.1.3 Coding and Iterative
Testing
The program or set of programs is developed. Each module of
the program is written using a suitable programming language
and then tested to see if it works. Iterative testing means
that modular tests are conducted, code amended, and tests
repeated until the module performs as required.
7.2.2 Decomposing a problem
We know any problem can be solved by using computer
system. There are four main computer components that are
needed to find a solution.
INPUT - The data used by the system PROCESS - The task that
should be performed
STORAGE - Data that needs to be stored in the OUTPUT - Information that
should be displayed
7.2.3 Methods used to design and
construct a solution to a problem
There are some methods to design and construct a solution to a problem.
Formal methods help us to understand clearly and effectively. These are
the formal methods that we used:
Structure diagrams
Flowcharts
Pseudocode
➢
Structure charts
Structure diagrams can be used to show top-down design in a diagrammatic
form.
Structure diagrams are hierarchical, showing how a computer system
solution can be
divided into sub-systems with each level giving a more detailed breakdown.
If necessary, each sub-system can be further divided.
Flowcharts
A flowchart shows
diagrammatically the
steps required to complete
a task and the order that
they are to be performed.
These steps, together with
the order, are called an
algorithm. Flowcharts are
an effective way to
communicate how the
algorithm that makes up a
system or sub-system
Begin/end
Terminator flowchart symbols are
used at the beginning and end of
each flowchart.
Process flowchart Symbols are used to show actions, for
example, when values are assigned to variables. If a process
has been defined elsewhere then the name of that process is
shown
INPUT and OUTPUT DECISIONS We know about “if” operator in HLL. It helps
The same flowchart symbol is us to make decisions. But it can also be “for”, “while” and
used to show the input of data “repeat”. Decision flowchart symbols are used to
and output of information decide which action is to be taken next; these can be used
for selection and repetition/iteration. There are always
two outputs from a decision flowchart symbol.
Pseudocode
Pseudocode is a simple method of showing an algorithm. It describes what the
algorithm does by using English key words that are very similar to those used in a
high level programming language. Data items to be processed by the algorithm are
given meaningful names in the same way that variables and constants are in a high-
level programming language. However, pseudocode is not bound by the strict
syntax rules of a programming language. It does what its name says, it pretends to
be programming code!
To ensure that pseudocode is easily understandable by others it is useful to be
consistent in the way that it is written.
The pseudocode for an assignment
statement
A value is assigned to an item/variable using the ←
operator. The variable on the left of the ← is assigned the value
of the expression on1.the
Basic Calculation:
right.
o Price = Cost + 2
A Trace table records the results of each step in an algorithm, showing the value of variables as
they change. The manual process of going through the algorithm step by step is called a dry run.
•
Create a column for each variable.
•Add a column for output.
During a dry run:
•Enter a new variable value in the
trace table whenever it changes.
•Record output values in the output
column.
Test Data: 9, 7, 3, 12, 6, 4, 15, 2, 8, 5. The output shows that the algorithm selects
the largest and smallest numbers from a list of ten positive numbers. The same
trace table can be used if the algorithm is presented in pseudocode.