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

Post on 23-Dec-2015

215 views 0 download

Tags:

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

- Meeting 5 –Making Decision

By: Felix Valentin, MBA

Today Topic:

• Evaluate Boolean expressions to make comparisons

• Use the logical comparison operators• Understand AND logic• Understand OR logic

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

Evaluate Boolean expressions to make comparisons

Flowchart and Pseudo code for Overtime Decision

Flowchart and Pseudo codefor Dental Plan Decision

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

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

• 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

Using a Negative Comparison

Using the Positive Equivalent of the Negative Comparison

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

• 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

• 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

• 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

• 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

• 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

Logic Table

AND True FalseTrue TRUE FALSEFalse FALSE FALSE

OR True FalseTrue TRUE FALSEFalse FALSE FALSE

Practice

• Create a pseucedo code and flowchart for condition below:

Price (USD) Status Result

< 200 A / B Open

< 200 C Close

200 – 1.000 A Close

200 – 1.000 B Open

200 – 1.000 C Close

> 1.000 A / C Open

> 1.000 B Close

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