Programming C#
  1. Consider the following code segment.

    int a = 3 + 2 * 3;
    int b = 4 + 3 / 2;
    int c = 7 % 4 + 3;
    double d = a + b + c;

    What is the value of d after the code segment is executed?

    1. 14.0
    2. 18.0
    3. 20.0
    4. 20.5
    5. 26.0
  2. Assume that x, y, and z are boolean variables that have been properly declared and initialized.

    Which of the following expressions is equivalent to !x || !y || z ?

    1. !(x && y) && z
    2. !(x && y) || z
    3. !(x || y) && z
    4. !(x || y) || z
  3. Which of the following will evaluate to true only if boolean expressions A, B, and C are all false?

    1. !A && !(B && !C)
    2. !A || !B || !C
    3. !(A || B || C)
    4. !(A && B && C)
    5. !A || !(B || !C)
  4. Assume that a and b are integers. The boolean expression

    !(a <= b) && (a * b > 0)

    will always evaluate to true given that

    1. a = b
    2. a > b
    3. a < b
    4. a > b and b > 0
    5. a > b and b < 0
  5. Assume that a and b are Boolean variables that have been initialized. Consider the following code segment.

    a = a && b;
    b = a | | b;

    Which of the following statements is true?

    I. The final value of a is the same as the initial value of a.

    II. The final value of b is the same as the initial value of b.

    III. The final value of a is the same as the initial value of b.

    1. I only
    2. II only
    3. III only
    4. I and II only
    5. II and III only
  6. Given that a, b, and c are integers, consider the boolean expression

    (a < b) || !((c == a * b) && (c < a))

    Which of the following will guarantee that the expression is true?

    1. c < a is false.
    2. c < a is true.
    3. a < b is false.
    4. c == a * b is true.
    5. c == a * b is true, and c < a is true.
  7. Assume that x and y have been declared and initialized with int values. Consider the following C# expression:

    (y > 10000) || (x > 1000 && x < 1500)

    Which of the following is equivalent to the expression given above?

    1. (y > 10000 || x > 1000) && (y > 10000 || x < 1500)
    2. (y > 10000 || x > 1000) || (y > 10000 || x < 1500)
    3. (y > 10000) && (x > 1000 || x < 1500)
    4. (y > 10000 && x > 1000) || (y > 10000 && x < 1500)
    5. (y > 10000 && x > 1000) && (y > 10000 && x < 1500)
  8. Which of the following best describes the value of the Boolean expression shown below?

    a && !(b || a)
    1. The value is always true.
    2. The value is always false.
    3. The value is true when a has the value false, and is false otherwise.
    4. The value is true when b has the value false, and is false otherwise.
    5. The value is true when either a or b has the value true, and is false otherwise.