Flowcharts adapted from A Visual Tool for Logic











- Slides: 11

Flowcharts adapted from A Visual Tool for Logic Design and Program Planning, by Dr. Donald Bell, Cal Poly, 1999 updated April, 2010

What Is a Flowchart? z. Diagram with lines (arrows) and symbols to show something works ycan show code works in a program xdefinition and symbols (programming) ycan also be used to help understand other processes xcriminal justice system flowchart (symbols somewhat different than for programming)

Flowcharts z. Reasons for using flowcharts ysimilar to reasons for using pseudocode z. Special symbols used in flowcharts z. Rules for Successive Refinement

Purpose of Flowcharts z. To plan your logic prior to writing your program z. Can be very helpful when you have complex conditional logic (the graphics help visualize the logic flow) z. Assists in applying "successive refinement" ("top down" analysis) z. Can also be used to document your logic ynot used as much with object oriented code

Successive Refinement z Equally applicable whether you use flowcharting or pseudocode z Start at the very "top level" y a one line statement of your program's purpose y break it down by stages into greater and greater levels of detail z Successive refinement stops when there is enough detail to write the program z Each flowchart symbol is a basic building block (like Tinker Toys or Lego blocks) y these are assembled into complex structures y assembled in specific ways

Flowcharting Symbols z Like pseudocode there are no fixed "standards", but there are conventions z Flowcharts use ovals, rectangles and diamonds yovals start and end the logic flow yrectangles are for imperative statements ydiamonds are for decisions z Some people use other symbols such as parallelograms for input and output, etc.

Rules for Applying Successive Refinement Using Flowcharts z. Can replace one rectangular block with several more detailed ones z. Can replace a rectangular block with one including logic or iteration (looping) z. Each block has one entry point, and one exit point (very important!) ybut different statements can enter it there z. Flow does not terminate until you get to a stop or end symbol

Rules for Applying Successive Refinement Using Flowcharts - 2 z. Start with a simple chart that summarizes the whole system (high level view) yuse separate symbols for each major aspect, e. g. , input, processing, output z. Decompose each major aspect into a more detailed flow chart ye. g. , input could decompose into: prompt user, read input, check input, if wrong give error message and prompt for good data

Flowcharts & OO Programs z. Flowcharts use a sequential logic ytop to bottom z. OO programming is often "event driven" yobjects fire methods in response to messages z. However flowcharting is suitable for developing code within methods

UML Diagrams z. Identify tasks (use cases) z. Identify which object should handle a task z. Identify messages sent between objects z. Draw objects and messages into a diagram yexample of a "use case diagram (which shows a class, properties, methods)

Review z. Draw flowcharts for sequence, selection and iteration control structures z. Draw a flowchart for code that counts the number of students with GPAs of 3. 0 or higher and then prints the total y. Will need to use sequence, selection and iteration