110 likes | 444 Views
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?. Diagram with lines (arrows) and symbols to show how something works can show how code works in a program
E N D
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? • Diagram with lines (arrows) and symbols to show how something works • can show how code works in a program • definition and symbols (programming) • can also be used to help understand other processes • criminal justice system flowchart (symbols somewhat different than for programming)
Flowcharts • Reasons for using flowcharts • similar to reasons for using pseudocode • Special symbols used in flowcharts • Rules for Successive Refinement
Purpose of Flowcharts • To plan your logic prior to writing your program • Can be very helpful when you have complex conditional logic (the graphics help visualize the logic flow) • Assists in applying "successive refinement" ("top down" analysis) • Can also be used to document your logic • not used as much with object oriented code
Successive Refinement • Equally applicable whether you use flowcharting or pseudocode • Start at the very "top level" • a one line statement of your program's purpose • break it down by stages into greater and greater levels of detail • Successive refinement stops when there is enough detail to write the program • Each flowchart symbol is a basic building block (like Tinker Toys orLego blocks) • these are assembled into complex structures • assembled in specific ways
Flowcharting Symbols • Like pseudocode there are no fixed "standards", but there are conventions • Flowcharts use ovals, rectangles and diamonds • ovals start and end the logic flow • rectangles are for imperative statements • diamonds are for decisions • Some people use other symbols such as parallelograms for input and output, etc.
Rules for Applying Successive Refinement Using Flowcharts • Can replace one rectangular block with several more detailed ones • Can replace a rectangular block with one including logic or iteration (looping) • Each block has one entry point, and one exit point (very important!) • but different statements can enter it there • Flow does not terminate until you get to a stop or end symbol
Rules for Applying Successive Refinement Using Flowcharts - 2 • Start with a simple chart that summarizes the whole system (high level view) • use separate symbols for each major aspect, e.g., input, processing, output • Decompose each major aspect into a more detailed flow chart • e.g., input could decompose into: prompt user, read input, check input, if wrong give error message and prompt for good data
Flowcharts & OO Programs • Flowcharts use a sequential logic • top to bottom • OO programming is often "event driven" • objects fire methods in response to messages • However flowcharting is suitable for developing code within methods
UML Diagrams • Identify tasks (use cases) • Identify which object should handle a task • Identify messages sent between objects • Draw objects and messages into a diagram • example of a "use case diagram (which shows a class, properties, methods)
Review • Draw flowcharts for sequence, selection and iteration control structures • Draw a flowchart for code that counts the number of students with GPAs of 3.0 or higher and then prints the total • Will need to use sequence, selection and iteration