CS110 LAB 4           Boolean Expressions


Instructor: Trish Cornez





PART I
LOGICAL OPERATORS: && ,   || ,   !



For the questions below, assume that p, q, and r are boolean expressions with the values true, true, and false, respectively. Find the value of each boolean expression.
  1. p && !q

  2. p && q || !r

  3. p && ! (q || r)

  4. !p && q

  5. p || q && r




PART II
RELATIONAL OPERATORS : < ,  >,   <= ,   >= ,   == ,   !=



Assume the following variables have been declared:

  int   m  = -5;
  int   n   = 8 ;
  char   c  = 'a';
  double   x  = -3.56;
  double   y  = 0.0;
  double   z  = 44.7;


For the questions below, find the value of the boolean expressions.

  1. m <= n

  2. -2 * m <= 8

  3. (x <= y) && (y <= z)

  4. ! (x < y)

  5. ! ((m <= n) && (x + z > y))

  6. !( m <= n) || ! ( x + z > y)

  7. ! (( m > n) && !(x < z))

  8. 0 <= m <= 10

  9. c == 97

  10. 0 <= m && m <= 10




PART III

  1. Write a boolean expression to express that x is nonzero.

  2. Write a boolean expression to express that x is strictly between -10 and 10.

  3. Write a boolean expression to express that both x and y are positive or both x and y are negative.

  4. Write a boolean expression to express that c is strictly uppercase.

  5. Write a boolean expression to express that c is a vowel.