Programming in C++ In C++ &the value O represents false ANY non-zero value represents true
11 In C++ ❖the value 0 represents false ❖ANY non-zero value represents true
Programming in C++ Comparing Strings e two objects of type string (or a string object and a C string) can be compared using the relational operators a character-by-character comparison is made using the ASCll character set values %if all the characters are equal, then the 2 strings are equal. Otherwise, the string with the character with smaller AScll value is the"lesser string 12
12 Comparing Strings ❖two objects of type string (or a string object and a C string) can be compared using the relational operators ❖a character-by-character comparison is made using the ASCII character set values ❖if all the characters are equal, then the 2 strings are equal. Otherwise, the string with the character with smaller ASCII value is the “lesser” string
Programming in C++ Examples for strings comparison string myState string your State; mystate=“ Texas” yourState=“ Maryland”; EXPRESSION VALUE my State = yourState false myState yourState true myState==“ Texas true myState<“ texas true why? Caution: all of the uppercase letters come before the lowercase letters 13
13 string myState; string yourState; myState = “Texas”; yourState = “Maryland”; EXPRESSION VALUE myState == yourState false myState > yourState true myState == “Texas” true myState < “texas” true why? Caution:all of the uppercase letters come before the lowercase letters. Examples for strings comparison
Programming in C++ Operator Meaning Associativity NOT Right Multiplication, Division, Modulus Left Addition Subtraction Left Less than Left Less than or equal to Left Greater than Left Greater than or equal to Left Is equal to Left Is not equal to Left 88 AND Left OR Left Assignment Right
14 Operator Meaning Associativity ! NOT Right *, / , % Multiplication, Division, Modulus Left + , - Addition, Subtraction Left < Less than Left <= Less than or equal to Left > Greater than Left >= Greater than or equal to Left == Is equal to Left != Is not equal to Left && AND Left || OR Left = Assignment Right
Programming in C++ LOGICAL EXPRESSION MEANING DESCRIPTION NOT p is false if p is true p is true if p is false 88 p ANd qp&&q is true if both p and g are true. It is false otherwise p‖q p oR q p‖! g is true if either p or g or both are true. It is false otherwise 15
15 LOGICAL EXPRESSION MEANING DESCRIPTION ! p NOT p ! p is false if p is true ! p is true if p is false p && q p AND q p && q is true if both p and q are true. It is false otherwise. p || q p OR q p || q is true if either p or q or both are true. It is false otherwise