Presentation is loading. Please wait.

Presentation is loading. Please wait.

Flowcharting: Decision Structure

Similar presentations


Presentation on theme: "Flowcharting: Decision Structure"— Presentation transcript:

1 Flowcharting: Decision Structure

2 Review What do each of the following symbols represent? A Terminal
Connector Input/Output Operation Process

3 Review Name the four flowchart structures. Sequence Decision (Today)
Case (Today) Repetition

4 Review: Sequence Structure
A series of actions are performed in sequence The pay-calculating example was a sequence flowchart.

5 Decision Structure One of two possible actions is taken, depending on a condition.

6 Decision Structure (if-else)
A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path YES NO

7 Decision Structure (if-else)
In the flowchart segment below, 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. YES NO is x > y? Process B Process A

8 Decision Structure(if-else)
The flowchart segment below shows how a decision structure is expressed. Flowchart What would this look like in code? if (x>y) { difference = x – y; } else difference = y - x; YES NO Calculate difference as x - y Calculate difference as y - x is x > y?

9 Decision Structure (if)
The flowchart segment below shows a decision structure with only one action to perform. It is expressed with only one process. Flowchart YES NO x > y? Calculate difference as x - y

10 Case Structure (if-else if)
One of several possible actions is taken, depending on the contents of a variable.

11 Case Structure (if-else if)
The structure below indicates actions to perform depending on the value in yearsEmployed. If yearsEmployed == 1 bonus is set to 200 If yearsEmployed == 2, bonus is set to 400 CASE yearsEmployed 1 2 Other SET bonus = 0 SET bonus = 200 SET bonus = 400 SET bonus = 800 If yearsEmployed == 0, bonus is set to 0 If yearsEmployed is any other value, bonus is set to 800

12 Module - Subprograms A program module (such as a procedure or function) is represented by a special symbol.

13 Call CalcPay With Input, store result in totalPay
Modules START END Read Input. Call CalcPay With Input, store result in totalPay Display “Total Pay: “ + totalPay The position of the module symbol indicates the point the module is executed. A separate flowchart MUST be constructed for the module. The module flowchart will have the subprogram name in the START terminal instead of START

14 Review What do each of the following symbols represent? Decision
Terminal Input/Output Operation Connector Process Module


Download ppt "Flowcharting: Decision Structure"

Similar presentations


Ads by Google