Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem Solving with Decission Structure

Similar presentations


Presentation on theme: "Problem Solving with Decission Structure"— Presentation transcript:

1 Problem Solving with Decission Structure
Chapter #5

2 Overview Logical decision structure Instruction: IF/THEN/ELSE
Logical application

3 Objectives Develop problems using the decision logic structure in conjunction with the sequential logic structure. Use problem-solving tools when developing a solution using the decision logic structure. Use nested decision instructions to develop a problem solution. Distinguish the different uses of straight-through, positive, and negative nested decision logic structures. Convert a positive decision logic structure to a negative decision logic structure.

4 What is critical thinking?
Q: What is the difference between a heuristic and algorithmic solution to a problem? The difference on algorithmic and heuristic solution is that algorithmic requires series of action, and heuristic is built on knowledge and experience

5 What is critical thinking?
A: There are set of steps H: There are no set of steps H: Relies on experience A: Doesn’t rely on experience? What are the definitions of …? (Big no)

6 Motivations Decission Structure comes in many forms
Logical operators are first key and most important

7 Logical Operations

8 Last week: Flowchart Diagram for the Sequential Structure

9 Decission Structure

10 Figure 6.1 Flowchart Diagram of the Decision Structure

11 Example : Single Condition
Assume you are calculating pay at an hourly rate and overtime pay (over 40 hours) at 1.5 times the hourly rate The decision to calculate pay would be stated in the following way: If the hours are greater than 40, Then the pay is calculated for overtime, or Else the pay is calculated in the usual way

12 Figure 6.2 Single Condition—Two Possible Actions or Sets of Actions

13 Figure 6.4 Straight-Through Logic—Example 1

14 Task Implement this flowchart with C++

15 Multiple If/Then/Else Instructions
There are three types of decision logic you will use to write algorithms for solutions consisting of more than one decision. These types of decision logic include straight through logic, positive logic, and negative logic.

16 Straight-through logic
Straight-through logic means that all of the decisions are processed sequentially, one after the other. There is no Else part of the instructions; the False branch always goes to the next decision, and the True branch goes to the next decision after the instructions for the True branch have been processed.

17 Figure 6.5 Another Example of Straight-Through Logic—Example 2

18 Positive logic Positive logic allows the flow of the processing to continue through the module instead of processing succeeding decisions, once the resultant of a decision is True. Whenever the resultant is False (the Else part of the decision), another decision in the sequence is processed until the resultant is True, or there are no more decisions to process. At that time, the False branch processes the remaining instructions.

19 Negative logic Negative logic is similar to positive logic except that the flow of the processing continues through the module when the resultant of a decision is False. Whenever the resultant is True, another decision is processed until the resultant is False, or there are no more decisions to process. At that time, the True branch processes the remaining instructions. Negative logic is the hardest to use and understand.

20 Nested If/Then/Else instructions
Decisions using positive and negative logic use nested If/Then/Else instructions Decisions using straight-through logic do not Nested If/Then/Else instructions are sets of instructions in which each level of a decision is embedded in a level before it; like nesting baskets, one goes inside the next.

21 Example : Nested If/Then/Else
The decission is if PayType = “Hourly” then the resultant is True and the instruction set for the True is processed This decision says, Are the hours worked greater than 40? If the answer is “yes,” the pay is processed at the overtime rate.

22 Figure 6.3 Nested If/Then/Else Instructions

23 Task Implement this flowchart with C++

24 Example : Nested If/Then/Else
Find the amount to charge people of varying ages for a concert ticket. When the person is under 16, the charge is $7; when the person is 65 or over, the charge is $5; all others are charged $10

25 Nested If/Then/Else vs. Straight-Through Logic

26 Task Implement this flowchart with C++

27 Figure 6.6 Positive Logic—Example 1

28 Figure 6.9 Negative Logic—Example 1

29 Figure 6.7 Positive Logic—Example 2

30 Figure 6.10 Negative Logic—Example 2

31 Figure 6.8 The Conditions in Figure 6.7 Set Up in a Different Way

32 Figure 6.11 The Conditions in Figure 6.10 Set Up in a Different Way

33 Figure 6.13 Four Ways to Design a Set of Conditions

34 Figure 6.13 Four Ways to Design a Set of Conditions

35 Figure 6.13 Four Ways to Design a Set of Conditions

36 Figure 6.13 Four Ways to Design a Set of Conditions

37 Four Ways to Design a Set of Conditions

38 Questions For what type of problems would you use the case logic structure?

39 Questions For which of the following would you use the case logic structure? State why or why not. The cost of a car given 10 models. The cost of a car given 7 ranges of the cost of cars. Population of a state given 50 states. Average temperature of a given month. Months having a given average temperature. Bonus given commission. Temperature zone given a city’s average temperature. Cost of books for a semester.

40 Problems Set up four different algorithms and flowcharts for calculating a student’s letter grade given the following (do not use straight-through logic):


Download ppt "Problem Solving with Decission Structure"

Similar presentations


Ads by Google