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 = 0;

while (x < 5)

{

      x++;

}

cout << x;

a.      0

b.      12345

c.      01234

d.      4

e.      5

f.        none of the above

 

  1. What is output by the following code fragment?

int x = 0;

while (x < 5)

{

      x += 2;

}

cout << x;

a.      246

b.      024

c.      4

d.      5

e.      6

f.        none of the above

 

  1. What is output by the following code fragment?

int x = 0;

while (x < 5)

{

      x += 3;

      cout << x;

}

a.      0

b.      03

c.      36

d.      3

e.      6

f.        none of the above

 


  1. The following expression has what type of value if c1 is a Circle that has been properly declared and initialized? In other words, what type of variable can this expression’s value be assigned to?

c1.get_center().get_x()

a.      Circle

b.      Point

c.      double

d.      Circle and/or Point

e.      Point and/or double

f.        Circle and/or Point and/or double

 

  1. What is the value of count after the following code fragment executes?

int count = 0;

Point p1(0,0);

while (p1.get_x() < 5)

{

      p1.move(2,1);

      count++;

}

 

    1. 0
    2. 2
    3. 3
    4. 4
    5. 5
    6. none of the above

 

  1. What are the possible values of the following expression?

rand() % 5 + 1

 

    1. 0 to 4 (integers only)
    2. 1 to 5 (integers only)
    3. 1 to 6 (any real or floating-point number)
    4. true or false
    5. any integer less than 6
    6. none of the above

 

  1. It is a syntax error to have a return statement in a void function (a function that has the return type of void).
    1. TRUE
    2. FALSE

 


  1. Given this function definition

int do_something(int x)

{

      if (x >= 100)

      {

            return x;

      }

      else if (x >= 50)

      { 

            return x + 50;

      }

      else

      {

            return 0;

      }

}

 

            What is the value of the following expression?

                                   

do_something(50)

 

    1. 0
    2. 50
    3. 100
    4. 150
    5. This function call should not be used as an expression.
    6. None of the above

 

  1. Given this function definition

void do_something_else(int x)

{

      cout << x + 50;

}

 

            What is the value of the following expression?

 

                                    do_something_else(50)

 

    1. 50
    2. 100
    3. This function call should not be used as an expression.
    4. None of the above

 

  1.  All return statements must return a value.
    1. TRUE
    2. FALSE