Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
189 views

(Program Flow Chart) : 5.2.1 Sequence

The document describes program flow chart symbols and constructs including sequence, selection, and iteration. It provides examples of each construct and explains how to connect multiple flow charts using connectors when the logic cannot fit on one page. Exercises are included at the end to design flow charts for various programming scenarios.

Uploaded by

Ali Shahab
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

(Program Flow Chart) : 5.2.1 Sequence

The document describes program flow chart symbols and constructs including sequence, selection, and iteration. It provides examples of each construct and explains how to connect multiple flow charts using connectors when the logic cannot fit on one page. Exercises are included at the end to design flow charts for various programming scenarios.

Uploaded by

Ali Shahab
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

(PROGRAM FLOW CHART)

Introduction
Program Flow Chart is a graphical representation of the program logic in solving
a problem. It uses the standard symbols in designing input, process, output of a
program. The program flow should be read from top to bottom, left to right.

5.1 Program Flow Chart Symbols


 Input / Output (parallelogram)

 Processing (rectangle)

 Decision (diamond)

 Terminal (racetrack)

Connector (circle)

 Program Flow

5.2 Three Program Constructs in Program Flow Chart

5.2.1 Sequence

 A sequence execution of processes. Each instruction is executed in a serial manner,


one after another.

 E.g.
DO
S1: GET number1

1
S2: GET number2
S3: answer = number1 / number2
S4: DISPLAY answer
ENDDO

Start

Get
number
1

Get
number
2

answer =
number1 /
number2

Display
answer

Stop

The above sequence must be followed in order to print out the answer. You get
two numbers, compute the answer which is the division of number1 over
number2. Eventually, after the computation, the answer is printed out.

If the sequence of S2 and S3 is reversed, there will be an error as there is no


input data stored in number2.

5.2.2 Selection

 Provide a decision point that allows one of two choices to be chosen.

2
 E.g. 1
DO
GET number1
GET number2
IF number2 = 0 THEN
DISPLAY "Division by zero error"
ELSE
DO
answer = number1/number2
DISPLAY answer
ENDDO
ENDDO

Start

Get
number
1

Get
number
2

yes
numbe Display
r2= 0? "Division
by zero
error"
no

answer =
number1 /
number2

Display
answer

Stop

3
The decision point or condition above is whether number2 is a zero. If condition
is true, i.e. number2 is a zero then the message of "Division by zero error" will
be displayed. If condition is false, i.e. number2 is not a zero, then computation
of number1 divide by number2 is carried out. The result of answer is then
displayed.
5.2.3 Iteration
 Repeat a set of instructions a number of times based on condition stated. This loop
will end when condition has been fulfiled.
 E.g. 1
DO
total = 0
GET number
WHILE number < 1000
DO
total = total + number
GET number
ENDDO
DISPLAY total
ENDDO

Start

total = 0

Get
number

no
numbe Display
total Stop
r<
1000?
yes

total = total +
number2

The condition stated above is whether number < 1000. If condition is true, i.e.
number is less than 1000, then number is accumulated as the total. After which,

4
you get another number. The next execution is going back to the while condition
to check if the condition is true, if yes, you accumulate the current number with
the previous numbers and get another number.

The loop or set of instructions will end when number is >= 1000, whereby the
accumulated total will be displayed.
 E.g. 2
FOR i = 1 TO 12
DO
result = i * 9
DISPLAY (i, "* 9 = " , result)
ENDDO

Start

i=1

no
i <= Stop
12?

yes

result = i * 9

Display (i,
"*9=",result)

i=i+1
A variable i is initialised to 1 and eventually be incremented by 1. If i is in
between 1 to 12 inclusive, a processing of i will be performed and the result
displayed. The followings are the expected output :

1*9=9

5
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
11 * 9 = 99
1 2* 9 = 108
5.3 Connectors
When you have a program where the logic cannot be represented in a flowchart
than can fit on one page, you use connectors to connect the flowcharts on
different pages. However, the use of connectors should be avoided if possible as
the logic of the program is more difficult to follow when they do not fit on a
page.
For instance, if a flowchart has six processing steps and a page can fit only three
steps, the connector come into use.

Start 1

Step 1 Step 4

Step 2 Step 5

Step 3 Step 6

1 Stop

page 1 page 2

On page 1, the number assigned in the connector matches up the number assigned in the
connector on page 2 to determine the next step in the flowchart.

Exercises

6
page 1

1. You, along with your friends, are having your favourite dinner tonight. It's starting
with soup. The main course is meatloaf, mashed potatoes and peas. In addition, you can
have your choice of two deserts: apple pie or chocolate cake. Unfortunately, there's just
enough dessert for you to select a piece of one or the other, not both.
Draw a flowchart showing the order in which you will be served the food items at dinner.
Start your flowchart with sitting down to dinner and end it with clearing your plate off
the table when you're through. Assume there is only enough food for one serving of each
item.

2. Draw a flowchart to represent the logic of a program that accept the input of a
series of number. The program will display "Even number" if number entered is
even number. Otherwise the program will display "Odd number".

3. Add the following logic to the flowchart that you have created in question 1.
The program will add up all even number until 999 is entered. The number of
data entered, number of even numbers and the total of even numbers will be
displayed.

4. Design a program flowchart based on the following scenario :


Prompt the user to enter his/her name and age and determine whether he/she is an
adult or not. If he/she is below 21 years old, the user would be a teenager else
he/she would be and adult.
The user would be prompted after each person, if he/she wishes to enter anymore
name. The program continues to run until the user enters "No" or "N".

5. Assume you have bank account that compounds interest on a yearly basis. For
example, if you deposit $100 for two years at 4 percent interest, at the end of one
year you will have $104. At the end of two years, you will have the $104 plus 4
percent of that, or $108.16. Using program flowchart, draw the logic for a
program that would read in a deposit amount, a term, and an interest rate, and
print out your running total for each year of the term.

6. Draw a flowchart for a program that accepts an amount entered through the
keyboard. Then, determine the discount rate allowed; 20% would be given to
any purchase of more than $1000, 10% to purchase of more than $500
(inclusive). Display the discount given and also the amount after the deduction
of the discount.

You might also like