Presentation is loading. Please wait.

Presentation is loading. Please wait.

Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.

Similar presentations


Presentation on theme: "Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts."— Presentation transcript:

1 Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts

2 2 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

3 3 Program Design 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

4 4 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

5 5 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

6 6 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 describe sequence, 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

7 7 Flowchart Symbols Wiley text: page 100 Auxiliary slide Many in Powerpoint

8 8 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.

9 9 Flowchart for a Sequence START END Input sales amount from customer Computer total amount Sales amount x.06 Print report Save in file Sale report Sale data Sale Instructions follow each other sequentially Sequential instructions Hard Drive Printed Report

10 10 Flowchart for a Loop Loop or repetition structure flowchart: Ask a question Answer is “Yes” Execute the loop Answer is “NO” Exit the loop Question

11 11 Flowchart for a Decision Decision or selection structure flowchart: IF --- THEN --- ELSE CASE statement Question Answer is “NO” (false) Answer is “YES” (true)

12 12 Flowchart for a Decision ASK THE QUESTION IF condition THEN instruction1 instruction2 as many instructions as needed as many structures (decision, sequential, looping) as needed ELSE instruction1 instruction2 as many instructions as needed as many structures (decision, sequential, looping) as needed ENDIF Continuation of the program (instructions and structures) TRUE path if the questions answer is true (YES) FALSE path if the questions answer is false (NO) 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)

13 13 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) IF A = Z THEN instructions/structures ENDIF ENDIF Nesting

14 14 Somewhere before this decision, data is placed in the variables HOURS and RATE IF HOURS > 40 THEN PAY = RATE * (40 + 1.5 * (HOURS – 40)) ELSE PAY = RATE * HOURS ENDIF Flowchart for a Decision Data is put into HOURS and RATE start end IF HOURS > 40 PAY = RATE * HOURS PAY= RATE * (40 + 1.5 * (HOURS – 40)) Example 1

15 15 Nested Decisions (IF – THEN – ELSE) Example 2 ENDIF

16 16 Example 3 Range Check ENDIF

17 17 Example 4 ENDIF


Download ppt "Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts."

Similar presentations


Ads by Google