Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 4: 10 minutes

 

  1. What is output by the following code fragment?

 

int x = 10;

while (x < 20)

{

      cout << x << “ “;

      x = x + 3;

}

 

a.      0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

b.      10 11 12 13 14 15 16 17 18 19 20

c.      10 12 14 16 18 20

d.      10 13 16 19 22

e.      10 13 16 19

f.        13 16 19 22

 

  1. What is output by the following code fragment?

 

int x = 10;

int sum = 0;

while (x < 20)

{

      sum = sum + x;

      x = x + 5;

}

cout << sum;

 

a.      0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

b.      10 15 20

c.      10 15

d.      15

e.      25

f.        None of the above

 

  1. A function with a return type of double must have a return statement.

 

a.      TRUE

b.      FALSE

 


  1. What is output by the following code fragment?

 

Circle c(Point(0,0), 5.0);

int count = 0;

while (c.get_center().get_x() < 3)

{

      c.move(2,1);

      count++;

                        }

                        cwin << Message(Point(0,0), count);

 

a.      0

b.      1

c.      2

d.      3

e.      4

f.        5

 

  1. Which set of inputs would cause the following code fragment to output 10?

 

int entry = 0;

int count = 0;

int sum = 0;

cout << “Enter positive integers (type negative integer to quit)\n”;

cin >> entry;

while (entry >= 0)

{

      sum = sum + entry;

      cin >> entry;

      count++;

}

cout << sum / count;

 

    1. 10 -1
    2. 0 20 -10 30
    3. 10 10 -20
    4. 0 10 20 -10 -1
    5. None of the above
    6. All of the above

 

  1. A function may be defined within another function?

 

    1. TRUE
    2. FALSE

 

  1. A function with a return type of void must NOT have a return statement.

 

    1. TRUE
    2. FALSE

 

  1. A return statement for a function that has a return type of int will always _______________.

 

    1. end the function’s execution and return to where the function was invoked (called).
    2. return an integer value.
    3. return to the beginning of the function.
    4. end the program.
    5. A and B are both true
    6. B and D are both true

 

  1. Given this function definition:

 

int max(int first, int second)

{

      if (first > second)

      {

            return first;

      }

      else

      {

            return second;

      }

}

 

Which of the following function invocations (calls) is valid? Assume the max function is invoked (called) from within the main function and that int variables f and s have been declared and initialized before the max function is invoked (called).

 

    1. int max(int first, int second)
    2. max(int f, int s)
    3. max(f, s)
    4. max(“first”, “second”)
    5. A and B are both valid
    6. B and C are both valid

 

  1. A call to the function do_something defined below can be used as an expression.

 

void do_something(int value)

{

      cout << value * value / 2;

}

 

    1. TRUE
    2. FALSE