0% found this document useful (0 votes)
67 views

Appendix D: Introduction To Flowcharting

This document provides an introduction to flowcharting by including examples of flowcharts for programs from earlier chapters. It discusses the basic components and structures of flowcharts, including symbols to represent starting/ending points, input/output operations, processes, and connecting multiple flowcharts. Specific examples are given to illustrate sequence structures and decision structures.

Uploaded by

Mai K Mohamed
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Appendix D: Introduction To Flowcharting

This document provides an introduction to flowcharting by including examples of flowcharts for programs from earlier chapters. It discusses the basic components and structures of flowcharts, including symbols to represent starting/ending points, input/output operations, processes, and connecting multiple flowcharts. Specific examples are given to illustrate sequence structures and decision structures.

Uploaded by

Mai K Mohamed
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Z04_GADD5886_06_SE_APP4 Page 1 Thursday, January 31, 2008 8:39 PM

Appendix D: Introduction
to Flowcharting

This appendix provides a brief introduction to flowcharting. It includes example flow-


charts for programs that appear in Chapters 1 through 6. In addition, a complete lesson
on flowcharting is included on the Student CD. The lesson is stored in a PowerPoint file
named Flowcharting.ppt.
A flowchart is a diagram that depicts the “flow” of a program. It contains symbols that
represent each step in the program. The figure shown here is a flowchart for Program 1-1,
the pay-calculating program in Chapter 1.

START

Display message
”How many
hours did
you work?”

Read hours

Display message
”How much
do you get
paid per hour?”

Read payRate

Multiply hours
by payRate.
Store result in
grossPay.

Display
grossPay

END

1
Z04_GADD5886_06_SE_APP4 Page 2 Thursday, January 31, 2008 8:39 PM

2 Appendix D: Introduction to Flowcharting

Notice there are three types of symbols in this flowchart: rounded rectangles (representing
terminal points), parallelograms (representing input/output operations), and a rectangle
(representing a process).

Terminal Input/Output Processes


Operations

The rounded rectangles, or terminal points, indicate the flowchart’s starting and ending
points. The parallelograms designate input or output operations. The rectangle depicts a
process such as a mathematical computation, or a variable assignment. Notice that the
symbols are connected with arrows that indicate the direction of program flow.

Connectors
Sometimes a flowchart is broken into two or more smaller flowcharts. This is usually done
when a flowchart does not fit on a single page, or must be divided into sections. A connec-
tor symbol, which is a small circle with a letter or number inside it, allows you to connect
two flowcharts.

In the figure below, the A connector indicates that the second flowchart segment begins
where the first flowchart segment ends.

START A

END
A
Z04_GADD5886_06_SE_APP4 Page 3 Thursday, January 31, 2008 8:39 PM

Appendix D: Introduction to Flowcharting 3

Flowchart Structures
There are four general flowchart structures:
• Sequence
• Decision
• Repetition
• Case
A sequence structure is a series of actions or steps, performed in order. The flowchart for
the pay-calculating program is an example of a sequence structure. The following flow-
chart is also a sequence structure. It depicts the steps performed in Program 2-20, from
Chapter 2.

Flowchart for Program 2-20

START

Calculate Regular
Wages as Base
Pay times
Regular Hours.

Calculate Overtime
Wages as
Overtime Pay
times Overtime
Hours.

Calculate Total
Wages as Regular
Wages plus
Overtime Wages.

Display
Total Pay

END

The following flowchart, which is another sequence structure, depicts the steps performed
in Program 3-15 (from Chapter 3). Notice the use of connector symbols to link the two
flowchart segments.
Z04_GADD5886_06_SE_APP4 Page 4 Thursday, January 31, 2008 8:39 PM

4 Appendix D: Introduction to Flowcharting

Flowchart for Program 3–15

START A

Ask user to enter


Ask user to enter
beginning
number of widgets
inventory value
sold at Store 2.
for all three stores.

Read begInv. Read sold.

Store begInv Subtract sold


in store1, from sold2.
store2, and
store3.
Ask user to enter
number of widgets
Ask user to enter sold at Store 3.
number of widgets
sold at Store 1.
Read sold.

Read sold.
Subtract sold
from store3.
Subtract sold
from store1.
Display inventory
values for all
A three stores.

END

The Decision Structure


In a decision structure, one of two possible actions is performed, depending on a condi-
tion. In a decision structure, a new symbol, the diamond, represents a yes/no question. If
the answer to the question is “yes,” the program flow follows one path. If the answer to
the question is “no,” the program flow follows another path. The following figure shows
the general form of a decision structure.
Z04_GADD5886_06_SE_APP4 Page 5 Friday, February 1, 2008 8:28 PM

Appendix D: Introduction to Flowcharting 5

NO YES

In the following flowchart segment, 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

The following flowchart depicts the logic of Program 4-8, from Chapter 4. The decision
structure shows that one of two possible messages is displayed on the screen, depending
on the value of the expression number % 2.
Z04_GADD5886_06_SE_APP4 Page 6 Friday, February 1, 2008 9:26 PM

6 Appendix D: Introduction to Flowcharting

Flowchart for Program 4–8


START

Ask user to enter


an integer.

Read number.

NO YES
number % 2
equal to 0?

Display Display
”Number is ”Number is
odd.” even.”

END

The Case Structure


In a case structure, one of several possible actions is taken, depending on the contents of a
variable. The following flowchart segment shows the general form of a case structure.

The following flowchart depicts the logic of Program 4–31, which is also from Chapter 4.
One of 4 possible paths is followed, depending on the value stored in the variable
feedGrade.
Z04_GADD5886_06_SE_APP4 Page 7 Thursday, January 31, 2008 8:39 PM

Appendix D: Introduction to Flowcharting 7

Flowchart for Program 4–31


Start

Ask the user to


enter the desired
feed grade.

Read input into


feedGrade.

case feedGrade

'a' 'b' 'c'


'A' 'B' 'C' Other

Display "30 cents Display "20 cents Display "15 cents Display "That is an
per pound". per pound". per pound". invalid choice".

End

Repetition Structures
A repetition structure represents part of the program that repeats. This type of structure
is commonly known as a loop. The following figure shows an example of a repetition
structure.

YES
x < y? Process A

Notice the use of the diamond symbol. A repetition structure 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. In
the flowchart segment above, the question “is x < y?” is asked. If the answer is yes, then
Z04_GADD5886_06_SE_APP4 Page 8 Thursday, January 31, 2008 8:39 PM

8 Appendix D: Introduction to Flowcharting

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 struc-
ture is exited.
There are two forms of repetition structure: pre-test and post-test. A pre-test repetition
structure tests its condition before it performs an action. The flowchart segment above
shows a pre-test structure. Notice that Process A does not execute at all if the condition “x
< y” is not true. The pre-test repetition structure is coded in C++ as a while loop.
A post-test repetition structure tests its condition after it performs an action. This type of
loop always performs its action at least once. The following flowchart segment shows an
example.

Process A

YES
x < y?

NO

The post-test repetition structure is coded in C++ as a do-while loop.


The following flowchart depicts the logic of Program 5-6, which appears in Chapter 5.

Flowchart for Program 5-6

START

number = 1.

Display Table
Headings.

YES Display number


number <= and number Add 1 to number.
10? Squared.

NO
END
Z04_GADD5886_06_SE_APP4 Page 9 Thursday, January 31, 2008 8:39 PM

Appendix D: Introduction to Flowcharting 9

Modules
A program module (such as a function in C++) is represented by the special symbol shown
below:

The position of the module symbol indicates the point the module is executed, as shown in
the following figure:

START

Read Input.

Call calc_pay
function.

Display results.

END

A separate flowchart can then be constructed for the module. The following figure shows
a flowchart for Program 6-19 from Chapter 6. The getBasePay and getOvertimePay
modules appear as separate flowcharts.
Z04_GADD5886_06_SE_APP4 Page 10 Thursday, January 31, 2008 8:39 PM

10 Appendix D: Introduction to Flowcharting

Flowchart for Program 6-19

Start
Start of
getBasePay

Ask the user to


enter the number
of hours worked.
No hours > Yes
BASE_HOURS?

Call
getBasePay basePay = basePay =
hoursWorked * BASE_HOURS *
PAY_RATE PAY_RATE

hours > Yes End of


BASE_HOURS? getBasePay

Call Start of
No getOvertimePay getOvertimePay

No hours > Yes


Calculate total pay. BASE_HOURS?

overtimePay = (hoursWorked
overtimePay = 0.0 - BASE_HOURS) *
PAY_RATE *
Display base pay, OT_MULTIPLIER
overtime pay, and total
pay.

End of
getOvertimePay
End

You might also like