CSCI 3300
Spring 2009
Exercises for Quiz 1

  1. What is the value of C++ expression 5 * 4 - 6 * 3 - 9?

    1. -7
    2. -19
    3. 1
    4. 11
    5. 33
    Answer

  2. What is the value of C++ expression 9/4 + 1?

    1. 1.25
    2. 2
    3. 2.25
    4. 3
    5. 3.25
    Answer

  3. Function g is defined below. What is the value of expression g(3)?

    1. 0
    2. 6
    3. 9
    4. 3
    5. 12

  4.   int g(int n)
      {
        if(n > 3) return 0;
        else return 2*n+3;
      }
    Answer

  5. Using function g from the preceding exercise, what is the value of expression g(g(3))? This previously had an incorrect answer.

    1. 0
    2. 9
    3. 18
    4. 21
    5. 25
    Answer

  6. What is the value of variable r after the program fragment below is finished? Do a careful hand simulation.

    1. 3
    2. 4
    3. 5
    4. 8
    5. 16
          int n = 1;
          int r = 1;
          while(n < 5)
          {
            r = r + r;
            n = n + 1;
          }
    Answer

  7. Suppose that variable y, of type double, already exists and has a value. Write a statement or sequence of statements that (1) creates a variable called frame of type double, and (2) makes frame hold value (y2 - 7y + 4)/9. Be sure to use C++ notation correctly. The expression shown is not in C++ notation, but in standard mathematical notation. Answer

  8. Suppose that variable u has type int, and has already been given a value. Write a statement or statements that create variable m, of type int, and make m hold the absolute value of u. For this exercise, do not use the C++ abs function, or any close relative of it. (The absolute value of 4 is 4, and the absolute value of -4 is 4.) Answer