the program design phases propose and evaluate solutions determine the most efficient solution...

30
The Program Design Phases Propose and evaluate solutions Determine the most efficient solution Develop and represent the algorithm Test and validate the solution Define the problem

Upload: scot-warner

Post on 22-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

The Program Design Phases

Propose and evaluate solutions

Determine the most efficient solution

Develop and represent the algorithm

Test and validate the solution

Define the problem

Programs are Solutions to Problems

Programmers can represent their solutions in several ways :

• Structure Charts• Pseudocode• Flowcharts

These are the tools used in structured programming

Structured Programming

• Structured program languages lend themselves to flowcharts, structure charts, and pseudocode.

• Structured programming languages work best where the instructions have been broken up into small, manageable parts (procedures/modules).

Pseudocode

• This device is not visual but is considered a “first draft” of the actual program.

• Pseudocode is written in the programmer’s native language and concentrates on the logic in a program — not the syntax of a programming language.

Flowcharts

A flowchart is a pictorial representation of all the steps in a process.( A picture is worth a 1000 words )

There are Block flowcharts,System flowcharts,Procedure flowcharts and Program flowcharts

PROGRAM FLOWCHARTSThese represent the flow of logic in a

program and help programmers “see” program design. They are also sometimes called logic flowcharts.

Flow charts are drawn in the design phase of programming.

A flowchart is comprised of specialised symbols and flow lines. Each symbol contains information about what must be done at that point; and the arrow shows the flow of execution.

PROGRAM FLOWCHARTS cont’d

… show the step by step sequence of operations carried out by a computer program

the start and end of the program the input and output operations how the data is processed the main sections of the program

Program flowcharts should be sufficiently detailed for the program code to be written directly from it, making it, therefore, just like pseudocode

PROGRAM FLOWCHARTS cont’d

The most common flowchart symbols are :

PROGRAM FLOWCHARTS cont’d

The start / end symbol

Each flowchart must begin and end with the terminator symbol. The word START or END is

written inside the oval

PROGRAM FLOWCHARTS cont’d

START

END

PROGRAM FLOWCHARTS cont’d

The process symbol

This indicates an operation such as a calculation Details are written in the rectangle and should

begin with a verb

PROGRAM FLOWCHARTS cont’d

Add number to subtotal

PROGRAM FLOWCHARTS cont’d

The input / output symbol

This marks the point at which we get data or give results. The input or output is written inside the

parallelogram.

PROGRAM FLOWCHARTS cont’d

Input name

PROGRAM FLOWCHARTS cont’d

The decision symbol

This is used where a decision has to be made in selecting the subsequent path to be followed. Note that while there is only one entry point to

the diamond there are at least 2 exits

PROGRAM FLOWCHARTS cont’d

Even number ?

No

Yes

PROGRAM FLOWCHARTS cont’d

The pre-defined process symbol

This is used to represent a process which is broken down elsewhere

PROGRAM FLOWCHARTS cont’d

Sort Marks

PROGRAM FLOWCHARTS cont’d

The connector symbols

Connector

Off-page connector

These are used to break and continue links without crisscrossing lines all over the place. So

they link with another part of the program or another page.

PROGRAM FLOWCHARTS cont’d

A B

A B

Drawing Flow Charts

• Organize the flowchart in modules

• Use standard symbols only, you can vary the size

but not the shape

• Try to keep the logic as flowing from top to bottom

and from left to right

• Do not cross flow lines

• Use a template if possible

• Add notes if necessary for clarity but not not clutter

PROGRAM FLOWCHARTS cont’d

Combining symbols

Sequence of steps

START

Step 1

Step 2

Step 3

END

PROGRAM FLOWCHARTS cont’d

Combining symbols

Decision (if statement)

n = sum + grade

N > 50?

Give certificate

END

YesNo

PROGRAM FLOWCHARTS cont’d

Combining symbols

Loops WHILE loop

( loops involve

a) decisions and branching {if statements} b) Returning to previous statements )

n = n + 1

N < 50?

< an action >

True

< action continuing program >

False

Combining symbols

Loops REPEAT loop

In a REPEAT loop the action

takes place before the first check

PROGRAM FLOWCHARTS cont’d

n = n + 1

N < 50?

< an action >

True < action continuing program >

False

Start

Sum = 0

Input price

Sum = sum + price

Moreitems?

Tax = sum x 0.15

Output sum, tax,

End

No

Yes

CASH REGISTER PROGRAM

Terminator. Shows the starting and ending points of the program. A terminator has flow lines in only one direction, either in (a stop node) or out (a start node).

Data Input or Output. Allows the user to input data and results to be displayed.

Processing. Indicates an operation performed by the computer, such as a variable assignment or mathematical operation.

Decision. The diamond indicates a decision structure. A diamond always has two Flow lines out. One flow line out is labeled the “yes” branch and the other is labeled the “no” branch.

Predefined Process. One statement denotes a group of previously defined statements. For instance, “Calculate m!” indicates that the program executes the necessary commandsto compute m factorial.

Connector. Connectors avoid crossing flow lines, making the flowchart easier to read. Connectors indicate where flow lines are connected. Connectors come in pairs, one witha flow line in and the other with a flow line out.

Off-page connector. Even fairly small programs can have flowcharts that extend severalpages. The off-page connector indicates the continuation of the flowchart on another page. Just like connectors, off-page connectors come in pairs.

Flow line. Flow lines connect the flowchart symbols and show the sequence of operations during the program execution.

Common Flowchart Symbols

Common Flowchart Symbols

FYI : Other Symbols

- - - - - - annotation / notes

tape disk display document

Benefits of Flowcharts

• Communication : a better way of communicating because they are visual

• Effective analysis : the visual nature allows quick grasp of program logic

• Aids in technical documentation

• Good guide when it is time to code

• Good aid when program maintenance becomes necessary

Draw Backs of Flowcharts

• When programs are large or complex, the chart becomes too complicated

• If alterations are required, the entire chart may have to be re-drawn

Because of this, the use of program flowcharts is actually in decline