Presentation is loading. Please wait.

Presentation is loading. Please wait.

- Meeting 5 – Making Decision By: Felix Valentin, MBA.

Similar presentations


Presentation on theme: "- Meeting 5 – Making Decision By: Felix Valentin, MBA."— Presentation transcript:

1 - Meeting 5 – Making Decision By: Felix Valentin, MBA

2 Today Topic: Evaluate Boolean expressions to make comparisons Use the logical comparison operators Understand AND logic Understand OR logic

3 Evaluate Boolean expressions to make comparisons The selection structure (sometimes called a decision structure) involved in programs is one of the basic structures of structured programming

4 Evaluate Boolean expressions to make comparisons

5 Flowchart and Pseudo code for Overtime Decision

6 Flowchart and Pseudo code for Dental Plan Decision

7 Using Logical Comparison Operators Usually, you can compare only values that are of the same type; that is, you can compare numeric values to other numeric values and character values to other characters For any two values that are the same type, you can decide whether: – The two values are equal – The first value is greater than the second value – The first value is less than the second value

8 Using Logical Comparison Operators In any Boolean expression, the two values used can be either variables or constants Such expressions are considered trivial because each always results in the same value: true for the first expression and false for the second Each programming language supports its own set of logical comparison operators, or comparison symbols, that express these Boolean tests

9 In addition to the three basic comparisons you can make, most programming languages provide three others For any two values that are the same type, you can decide whether: – The first is greater than or equal to the second – The first is less than or equal to the second – The two are not equal Using Logical Comparison Operators

10 Using a Negative Comparison

11 Using the Positive Equivalent of the Negative Comparison

12 Using Logical Comparison Operators Besides being awkward to use, the not equal to comparison is the one most likely to be different in the various programming languages you may use Although NOT comparisons can be awkward to use, there are times when your meaning is clearest if you use one

13 An AND situation requires a nested decision or a nested if; that is, a decision “inside of” another decision When you nest decisions because the resulting action requires that two conditions be true, you must decide which of the two decisions to make first Logically, either selection in an AND situation can come first However, when there are two selections, you often can improve your program’s performance by making an appropriate choice as to which selection to make first Understanding AND Logic

14 Most programming languages allow you to ask two or more questions in a single comparison by using a logical AND operator If you want to select employees who carry both medical and dental insurance, you can use nested ifs, or you can include both decisions in a single statement by writing empDentalIns = “Y” AND empMedicalIns = “Y”? Understanding AND Logic

15 Most programming languages allow you to ask two or more questions in a single comparison by using a logical AND operator If you want to select employees who carry both medical and dental insurance, you can use nested ifs, or you can include both decisions in a single statement by writing empDentalIns = “Y” AND empMedicalIns = “Y”? Understanding AND Logic

16 Most programming languages allow you to ask two or more questions in a single comparison by using a logical OR operator When you use the logical OR operator, only one of the listed conditions must be met for the resulting action to take place Understanding OR Logic

17 Most programming languages allow you to ask two or more questions in a single comparison by using a logical OR operator When you use the logical OR operator, only one of the listed conditions must be met for the resulting action to take place Understanding OR Logic

18 Logic Table ANDTrueFalse TrueTRUEFALSE FalseFALSE ORTrueFalse TrueTRUEFALSE FalseFALSE

19 Practice Create a pseucedo code and flowchart for condition below: Price (USD)StatusResult < 200A / BOpen < 200CClose 200 – 1.000AClose 200 – 1.000BOpen 200 – 1.000CClose > 1.000A / COpen > 1.000BClose

20 Case Project Create a pseucedo code and flowchart for Shio and zodiac application Example : – User Input Birth Date : 30 April 1988 – Shio : Dragon – Zodiac : Taurus


Download ppt "- Meeting 5 – Making Decision By: Felix Valentin, MBA."

Similar presentations


Ads by Google