Sunteți pe pagina 1din 51

Flowcharts

Dr. Aliaa Youssif BIS101

Chapter objectives

After completing this chapter, you will be able to: Identify the approaches to solve a programming problem. Describe the steps to program development. Demonstrate the principles and use of flow-charting.
2

Development Cycle Problem Solving


Analysis Design Implement Test

debugging and testing


3

Software Development Process


Define the problem clearly Analyze the problem
Design an algorithm Code (Implement) the algorithm Test the code Document the system
4

Algorithms

To solve a problem, you got to figure out how to solve it by yourself. To make a computer solve a problem, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal. Algorithm: Sequence of step-by-step instructions that will produce a solution to a problem

Flowcharts

A flowchart is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem. Notation that is often used during the design stage of the software life cycle for quick and easy understanding of a programs flow.
6

Flowcharts

Flowcharts

Basic Flowchart symbols


Decision Start End

Process Input/Output

1
9

Start and Ending Blocks


Start End

These blocks are used to start and end a process or program. These blocks should contain simple labels to indicate the process or program.
10

Input/Output Block
Input/Output

This block can represent either input or output statements. This block should be labeled with a brief description of the input or output.
11

Process Block
Process

The process block represents some operation carried out on an element of data. This could be a calculation. This block should be labeled with a brief description of the process being carried out.
12

Decision Block
Decision

The decision block should be a True/False choice. The label on the block should contain the question to the decision that should be made.
13

Continuation symbol

Continuation symbol Which is used to continue the flowchart in another page

14

How to use these Blocks

We can imagine using these blocks to build up a representation of your program.

15

Guidelines for Flowcharting

In drawing a proper flowchart, all necessary requirements should be listed out in logical order. The flowchart should be clear, neat and easy to follow. The usual direction of the flow of a procedure or system is from left to right or top to bottom. Only one flow line should come out from a process symbol.

16

Guidelines for Flowcharting

Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

17

Guidelines for Flowcharting

Only one flow line is used in conjunction with terminal symbol

End

start

18

Guidelines for Flowcharting

Write within standard symbols briefly. As necessary, you can use the annotation symbol to describe data or computational steps more clearly.

19

Guidelines for Flowcharting

If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication. Ensure that the flowchart has a logical start and End. It is useful to test the validity of the flowchart by passing through it with a simple test data.
20

Advantages of using flowcharts

Communication: Flowcharts are better way of communicating the logic of a system to all concerned. Effective analysis: With the help of flowchart, problem can be analysed in more effective way. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.

21

Advantages of using flowcharts

Efficient Coding: The flowcharts act as a guide during the systems analysis and program development phase. Proper Debugging: The flowchart helps in debugging process. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part

22

START

Example: Pay-calculating program

Display message How many hours did you work?

A flowchart is a diagram that depicts the flow of a program. The figure shown here is a flowchart for the paycalculating program.

Read Hours

Display message How much do you get paid per hour?

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

Example:

START
Display message How many hours did you work?

Rounded Rectangle

Pay-calculating program
Notice there are three types of symbols in this flowchart:

Read Hours

Display message How much do you get paid per hour?

Parallelogram

rounded rectangles parallelograms a rectangle

Read Pay Rate

Rectangle

Multiply Hours by Pay Rate. Store result in Gross Pay.

Each symbol represents a different type of operation.

Rounded Rectangle

Display Gross Pay

END

START

Terminal

Example: Pay-calculating program

Display message How many hours did you work?

Terminals

Read Hours

represented by rounded rectangles indicate a starting or ending point


START

Display message How much do you get paid per hour?

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

Terminal
END

Example: Pay-calculating program

START
Display message How many hours did you work?

Input/Output Operations

Read Hours

represented by parallelograms indicate an input or output operation

Display message How much do you get paid per hour?

Input/Output Operation

Read Pay Rate

Display message How many hours did you work?

Multiply Hours by Pay Rate. Store result in Gross Pay.

Read Hours

Display Gross Pay

END

Example:

START
Display message How many hours did you work?

Pay-calculating program
Processes

Read Hours

represented by rectangles indicates a process such as a mathematical computation or variable assignment


Multiply Hours by Pay Rate. Store result in Gross Pay.

Display message How much do you get paid per hour? Read Pay Rate

Process

Multiply Hours by Pay Rate. Store result in Gross Pay.


Display Gross Pay

END

START

Stepping Through the Flowchart


How many hours did you work?

Display message How many hours did you work?

Output Operation

Read Hours

Display message How much do you get paid per hour?

Read Pay Rate

Variable Contents: Hours: ? Pay Rate: ? Gross Pay: ?

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

START

Stepping Through the Flowchart


How many hours did you work? 40

Display message How many hours did you work?

Input Operation (User types 40)

Read Hours

Display message How much do you get paid per hour?

Read Pay Rate

Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ?

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

START

Stepping Through the Flowchart


How much do you get paid per hour?

Display message How many hours did you work?

Read Hours

Output Operation

Display message How much do you get paid per hour?

Read Pay Rate

Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ?

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

Stepping Through the Flowchart


How much do you get paid per hour? 20

START
Display message How many hours did you work?

Read Hours

Display message How much do you get paid per hour?

Input Operation (User types 20)

Read Pay Rate

Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: ?

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

Stepping Through the Flowchart


How much do you get paid per hour?

START
Display message How many hours did you work?

Read Hours

Display message How much do you get paid per hour?

Read Pay Rate

Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: 800

Process: The product of 40 times 20 is stored in Gross Pay

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

Stepping Through the Flowchart


Your gross pay is 800

START
Display message How many hours did you work?

Read Hours

Display message How much do you get paid per hour?

Read Pay Rate

Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: 800

Multiply Hours by Pay Rate. Store result in Gross Pay.

Output Operation

Display Gross Pay

END

Four Flowchart Structures


Sequence Decision Repetition

Sequence Structure

a series of actions are performed in sequence The pay-calculating example was a sequence flowchart.

Decision Structure

One of two possible actions is taken, depending on a condition.

Decision Structure

A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path
NO YES

Decision Structure

In the flowchart segment below, the question is x < y? is asked. If the answer is no, then process A is performed. If the answer is yes, then process B is performed.
NO YES

x < y?

Process A

Process B

Decision Structure

The flowchart segment below shows how a decision structure.


Flowchart

NO
x < y?

YES

Calculate a as x plus y.

Calculate a as x times 2.

Decision Structure

The flowchart segment below shows a decision structure with only one action to perform.
Flowchart

NO
x < y?

YES

Calculate a as x times 2.

Repetition Structure

A repetition structure represents part of the program that repeats. This type of structure is commonly known as a loop.

Repetition Structure

Notice the use of the diamond symbol. A loop tests a condition, and if the condition exists, it performs an action. Then it tests the condition again. If the condition still exists, the action is repeated. This continues until the condition no longer exists.

Repetition Structure

In the flowchart segment, the question is x < y? is asked. If the answer is yes, then Process A is performed. The question is x < y? is asked again. Process A is repeated as long as x is less than y. When x is no longer less than y, the repetition stops and the structure is exited.
x < y? YES Process A

Repetition Structure

The flowchart segment below shows a repetition structure.


Flowchart

x < y?

YES

Add 1 to x

Examples of using flowcharts


Example 1 Draw a flowchart to find the sum of first 50 natural numbers.

45

Examples of using flowcharts


Example 2
Draw a flowchart to find the largest of three numbers A,B, and C.

46

Examples of using flowcharts


Example 3
Draw a flowchart for computing factorial N (N!) Where N! = 1 x 2 x 3 x N .

47

Start

Examples of using flowcharts


Example 4
If you invest a capital of money, C (e.g. C=100,000 LE) in a bank with annual interest rate, R (e.g. R=12%). What is your total money, T you get each year (I) during a period of N years (e.g. N=10 years) given that the total money, T you get after I years is given by T = C (1+R)I

C, N, R I=1

T =C (1 + R)I

I,T I=I+1 No I=N Yes End


48

Examples of using flowcharts


Example 5

49

Examples of using flowcharts


Example 6 Draw a flow chart to perform S= 1+3+5+..+N

50

Flowchart Assignments
Draw a flowchart to find the sum of the even numbers in a given series from 1 to N. Draw a flowchart to compute the sum of squares of integers from 1 to 50 Draw a flowchart to perform S=1+1/2+1/3+1/4+..+1/100. Draw a flowchart to perform S = 1 - + 1/3 - +-1/100 Draw a flowchart to perform S= 1 + 1/3 + 1/5 + 1/7 +..+ 1/99. 51

S-ar putea să vă placă și