HW #2: Solutions to Questions

The solution to the programming assignment is here.

1. A leap year takes place when the year is divisible by 4, unless the year is divisible by 100 and not by 400.
Write a C++ expression that returns true only if year is a leap year.

(year % 4 == 0) && !((year % 100 == 0) && (year % 400 != 0))

2. Simplify the expression:
   X && Y || X && !Y

X

3. Simplify the expression:
   !!(!(!X || !Y) && Z)

X && Y && Z
4. Given X = true, Y = false, and Z = true, evaluate
   a) the expression in #2
   b) the expression in #3
a) true
b) false


Main Page