Vous êtes sur la page 1sur 19

Flowcharts

A flowchart is a graphical method of representing an algorithm.

Pseudocode
start read num1,num2, num3 Average =(num1+num2+num3)/3 print average Stop.

Flowcharts
Flowcharts use special geometrical objects to designate the basic steps of a program, which are: Input, processing and output

The four basic shapes are:


used for input and output operations - Input/output
Parallelogram box

Rectangle used to represent processing/assignment operations process box Decision used to represent Conditional and loop constructs. -Decision box An elliptical shape used to represent Start/Stop - Terminal box

Special symbol:
The connector symbol is a small circle with a number or letter inscribed therein and is used where flowchart cannot fit on a single page.
Flowchart Section 1

Flowchart Section 2

Flowchart Section 3

Examples of how various control structures are depicted in a flowchart:


1. Sequence:
A
do A

do B

Examples of how various control structures are depicted in a flowchart:


1. Selection (Decision):
No C Yes
If C is true then
do E Else do D

Examples of how various control structures are depicted in a flowchart:


1. Loop (Repetition):
While F is true
do G

Yes F G

No

Flowchart version of the Average Algorithm


Start
This example uses only the sequential structure.

Read num1,num2,num3

Average = (num1+num2+num3)/3

Print Average

Stop

Consider the following algorithm:


Read rate, hoursWorked basicPay = rate *40 Overtime = hoursWorked 40 If (overtime>0) then wages = BasicPay +(overtime*2*rate) Else wages = rate * hoursWorked Endif Print wages Stop. Question:

This algorithm calculates the wages (including overtime) due to an employee based on the number of hours worked.

START Read rate, hoursworked

BasicPay = hoursworked * 40

Overtime = hoursworked - 40

Yes
Wages = BasicPay + (Overtime *2*rate)

No
Overtime > 0 Wages = rate* hoursworked

Print Wages STOP

Specimen Q1
The variable CustBalance stores the amount of money owed by customers. CustBalance is MOST likely of data type: Integer Character Real Array

A. B. C. D.

Specimen Q2
a. Define the term flowchart. 1mk

Specimen Q2
b. The following symbols are used when drawing a program flowchart. Give the name of EACH of the program flowcharting symbols shown below.
START STOP

(i) (ii)

(iii)

Specimen Q2
b. The following symbols are used when drawing a program flowchart. Give the name of EACH of the program flowcharting symbols shown below.

(iv)
Yes

No

Specimen Q2
b. The following symbols are used when drawing a program flowchart. Give the name of EACH of the program flowcharting symbols shown below.

(v)
1 1

Specimen Q2
c. Draw a flowchart to obtain TWO values and print the larger of the TWO values.

Start Read Value1, Value2 If Value1 > Value2 then Print Value1 Else Print Value2 Endif Stop

Specimen Q3
1. Draw a flowchart to represent the algorithm below:
INPUT X, Y, Z Y=X+Y X=X-Y Y=X+Y IF X > Y THEN Z=X+Y-Z ELSE Z=X+Y+Z ENDIF PRINT X, Y, Z

Specimen Q3
2. Draw a flowchart to represent the algorithm below:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. begin J=2 C=1 while (J < 99) print J J=J+2 C= C + 1 endwhile Print C Print J end

Vous aimerez peut-être aussi