170 likes | 209 Views
Chapter 2: Flowcharts. Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake. Design the program. Create a detailed description of program Use charts or ordinary language (pseudocode) Identify algorithms needed
E N D
Chapter 2:Flowcharts Extended Prelude to Programming Concepts & Design, 3/e byStewart Venit and Elizabeth Drake
Design the program • Create a detailed description of program • Use charts or ordinary language (pseudocode) • Identify algorithms needed • Algorithm: a step-by-step method to solve a problem or complete a task • Algorithms must be: • Well defined • Well ordered • Must produce some result • Must terminate in a finite time
Modular programming Determine the major tasks that the program must accomplish. Each of these tasks will be a module. Some modules will be complex themselves, and they will be broken into submodules, and those submodules may also be broken into even smaller submodules. This is called top-down design Program Design
Documentation for other programmers • In-program documentation (remarks) • Program maintenance manual • For programming experts to help them fix or enhance code written by other programmers • Design documentation • Written by programmer to explain rationale behind methods and code used • Trade Study documentation • A research tool • An attempt to find the best solution
Structured Programming • A method for designing and coding programs in a systematic, organized manner • It combines the principles of top-down design, modularity and the use of the three accepted control structures of sequence, repetition and selection • Sequence, repetition and selection can be expressed in pseudocode, or with flowcharts
Flowcharts • A tool for programmers to design programs • Describes the flow of a program module’s execution with diagrams • Completely different from hierarchy charts • Connected symbols are used to describesequence, repetition, and selection structures • Some prefer to use flowcharting to learn how to express algorithms, and others prefer to use pseudocode • Many programs are designed with a combination of pseudocode and flowcharts
Flowchart Symbols Wiley text: page 100Auxiliary slideMany in Powerpoint
Control Structures • Sequence –in sequential order. • The simplest of control structures – start at the beginning and continue in sequential order. • Repetition – repeat statements more than once • Also called a loop, it needs a stop condition, i.e, the program will continue to loop until some condition is met. • Selection – selectively execute statements • Called a branch, it requires a condition to determine when to execute statements.
Flowchart for a Sequence START Instructions follow each other sequentially Input sales amount from customer Sale Sequential instructions Computer total amount Sales amount x .06 Print report Sale report Hard Drive Printed Report Sale data Save in file END
Flowchart for a Loop Loop or repetition structure flowchart: Ask a questionAnswer is “Yes” Execute the loop Answer is “NO” Exit the loop Question
Flowchart for a Decision Decision or selection structure flowchart: IF --- THEN --- ELSE CASE statement Question Answer is “NO” (false) Answer is “YES” (true)
Flowchart for a Decision ASK THE QUESTION IF condition THEN instruction1 instruction2 as many instructions as needed as many structures (decision, sequential, looping) as neededELSE instruction1 instruction2 as many instructions as needed as many structures (decision, sequential, looping) as neededENDIFContinuation of the program (instructions and structures) TRUE path if the questions answer is true (YES) IF condition THEN as many instructions as needed as many structures (decision, sequential, looping) as needed ENDIF TRUE path if the questions answer is true (YES) FALSE path if the questions answer is false (NO)
Flowchart for a Decision CONDITIONS A < B (A & B are the same data type (numeric or alphanumeric) X + 5 >= Z (X and Z are numeric data types) E < 5 (E is a numeric data type) F > 10 (F is a numeric data type) IFA < BTHEN instructions/structuresELSEIFX + 5 >= ZTHEN instructions/structuresENDIFENDIF Nesting
start Data is put into HOURS and RATE IFHOURS > 40 PAY= RATE * (40 + 1.5 * (HOURS – 40)) PAY = RATE * HOURS end Flowchart for a Decision Example 1 Somewhere before this decision, data is placed in the variables HOURS and RATEIF HOURS > 40 THEN PAY = RATE * (40 + 1.5 * (HOURS – 40))ELSE PAY = RATE * HOURSENDIF
Nested Decisions (IF – THEN – ELSE) Example 2 ENDIF ENDIF
Example 3 ENDIF Range Check ENDIF ENDIF
Example 4 ENDIF ENDIF ENDIF