Programming in C++ Logic EXpression >Alogic expression(Boolean expression) is made up of logical values and operations )Every logical expression has one of two values: true or false. > Here are some examples i A Boolean variable or constant iAn expression followed by a relational operator followed by an expression ii. A logical expression followed by a logical operator followed by a logical expression
6 Logic Expression ➢A logic expression (Boolean expression) is made up of logical values and operations. ➢Every logical expression has one of two values: true or false. ➢Here are some examples: i. A Boolean variable or constant ii.An expression followed by a relational operator followed by an expression iii. A logical expression followed by a logical operator followed by a logical expression
Programming in C++ bool Data Type type bool is a built-in type consisting of just 2 values, the constants true and false True and false are reserved words in C++, not variable names or string owe can declare variables of type bool bool hasFever; // true if has high temperature bool isSenior; //true if age is at least 55
7 bool Data Type ❖type bool is a built-in type consisting of just 2 values, the constants true and false ❖True and false are reserved words in C++, not variable names or string ❖we can declare variables of type bool bool hasFever; // true if has high temperature bool isSenior; // true if age is at least 55
Programming in C++ The operators used in logical expressions )6 Relational Operators )3 Logical Operators &1
8 The operators used in logical expressions ➢6 Relational Operators < <= > >= == != ➢3 Logical Operators ! && ||
Programming in C++ 6 Relational Operators are used In expressions of form. ExpressionA Operator EXpression B For example: temperature humidity B*B-4.0*A*C>0.0 abs(number 35 initial Q
9 are used in expressions of form: ExpressionA Operator ExpressionB For example: temperature > humidity B * B - 4.0 * A * C > 0.0 abs (number ) == 35 initial != ‘Q’ 6 Relational Operators
Programming in C++ int x, y: X=4 y=6; EXPRESSION VALUE x<y true x+2<y false xI=y true x+3>=y true y==X false y==x+2 true y=x+3 7(true) aution: Don't confuse the assignment operator() and the relational operator (= 10
10 int x, y ; x = 4; y = 6; EXPRESSION VALUE x < y true x + 2 < y false x != y true x + 3 >= y true y == x false y == x+2 true y = x + 3 7 (true) Caution: Don’t confuse the assignment operator (=) and the relational operator (==)