CS C++
Quiz 2
  1. The expression !((x > y) && (y <= 3)) is equivalent to which of the following?
    (a) (x > y) && (y <= 3)
    (b) (x > y) || (y <= 3)
    (c) (x < y) || (y >= 3)
    (d) (x <= y) || (y > 3)
    (e) (x <= y) && (y > 3)

  2. By the rules of short-circuit evaluation, in the following expression,
    p || (n < 3)
    (a) if p is true, then n < 3 will not be evaluated
    (b) if p is false, then n < 3 will not be evaluated
    (c) if p is true, then n < 3 will be evaluated
    (d) none of the above

  3. What numbers are printed out when the following for loop is executed?
        for (i = 0; i < 12; i++)
            cout << i + 1 << endl;
    
    (a) the numbers 0 through 12 (including 0 and 12)
    (b) the numbers 1 through 12 (including 1 and 12)
    (c) the numbers 0 through 11 (including 0 and 11)
    (d) the numbers 1 through 11 (including 1 and 11)

  4. Assume that the following definitions have been made.
        int num = 10;
        int sum;
    
    Which of the following code segments correctly computes the sum of the first 10 multiples of 5 (i.e., 5, 10, ..., 50)?
    (a)
    sum = 5;
    while (num > 1)
    {
        sum += sum;
        num--;
    }
    (d)
    sum = 0;
    while (num >= 0)
    {
        num--;
        sum += 5 * num;
    }
    (b)
    sum = 5;
    while (num > 0)
    {
        sum += sum;
        num--;
    }
    (e)
    sum = 0;
    while (num > 0)
    {
        sum += 5 * num;
        num--;
    }
    (c)
    sum = 0;
    while (num > 0)
    {
        num--;
        sum += 5 * num;
    }
  5. Write a program that inputs a list of integers, terminated by entering 0, then displays the number of even numbers included in the list.

  6. Write a for loop to print out the squares of the first 8 odd numbers (that is, 1, 9, 25, 49, 81, 121, 169, 225). Your solution should use only one variable.