1 / 13

ECE 1305 Introduction to Engineering and Computer Programming

ECE 1305 Introduction to Engineering and Computer Programming. Section 10 Boolean Expressions. Boolean Expressions. Boolean expressions are expressions that are either true or false. Comparison Operators such as > (greater than) are used to compare variables and/or numbers. Example:

Download Presentation

ECE 1305 Introduction to Engineering and Computer Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 1305Introduction to Engineering and Computer Programming Section 10Boolean Expressions

  2. Boolean Expressions • Boolean expressions are expressions that are either true or false. • Comparison Operators such as > (greater than) are used to compare variables and/or numbers. • Example: (hours > 40) • The parentheses act as a function that returns a logical true or false.

  3. Relational and Equality Operators

  4. C++ Relational and Equality Operators int kIce = 273; int kTemp = 250; char init = ’J’; double pressure = 37.2; double MAX_PRESSURE = 38.5; (pressure < MAX_PRESSURE) true (kTemp <= kIce) true (init > ’K’) false (250 >= kTemp) true

  5. C++ Relational and Equality Operators int kIce = 273; int kTemp = 250; char init = ’J’; double pressure = 37.2; double MAX_PRESSURE = 38.5; (init == ’Q’) false (kIce != kTemp) true (kTemp + 30 > kIce) true (kTemp % 2 == 1) false

  6. Logical Operators • More complicated logical statements may be formed using the AND operator (&&) or the OR operator (||) or the NOT operator ( ! ).

  7. Logical Operators • AND Operator (&&)

  8. Logical Operators • OR Operator (||)

  9. Logical Operators • NOT Operator (!)

  10. C++ Relational and Equality Operators int kIce = 273; int kTemp = 250; char init = ’J’; double pressure = 37.2; double MAX_PRESSURE = 38.5; (kIce > 250 && kIce < 280) true (pressure > 40 || init == ’J’) true !(init > ’K’) true (250 >= kTemp && kIce != 273) false (kIce != 273 && 250 >= kTemp) false (short-circuit evaluation)

  11. Precedence of Operators

  12. Boolean Data Type int age = 50; int yearsService = 30; bool eleigible; eligible = (age + yearsService) > 85; assigns the variable eligible the value false

  13. DeMorgan’s Theorem • bool A; • bool B; • !(A && B) = !A || !B • !(A || B) = !A && !B

More Related