Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 7: 10 minutes

 

 

Use the following declaration statement for the next 4 questions.

                                   

vector<double> v(100);

 

  1. How many elements does the vector v have?

 

a.       0

b.      1

c.       99

d.      100

e.       101

f.        none of the above

 

  1. What is the index number of the last element of the vector v?

 

a.       0

b.      1

c.       99

d.      100

e.       101

f.        none of the above

 

  1. What is the index number of the first element of the vector v?

 

a.       0

b.      1

c.       99

d.      100

e.       101

f.        none of the above

 

  1. Which of the following outputs the entire contents of the vector v?

 

a.       cout << v;

b.      for (int i = 0; i < 100; i++) cout << v[i] << “ “;

c.       for (int i = 1; i <= 100; i++) cout << v[i] << “ “;

d.      for (int i = 0; i < v.size(); i++) cout << v[i] << “ “;

e.       for (int i = 1; i <= v.size(); i++) cout << v[i] << “ “;

f.        B and D

 


  1. The following declaration of the vector s is a legal C++ statement?

vector<string> s;

 

    1. TRUE
    2. FALSE

 

 

Use the following code fragment for the next 3 questions

(I recommend writing out the vector’s contents)

vector<int> v(2);

v[0] = 10;

v[1] = 20;

for (int i = 1; i < 3; i++)

{

      v.push_back(i);

}

 

 
 

 

 

 

 

 

 

 

 

 

 


  1. What is the value of v[2]?

 

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

 

  1. What value will be returned by the function call v.size()?

 

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

 

  1. What will be the value of the last element of v after the following statement is executed?

v.pop_back();

 

    1. 10
    2. 20
    3. 1
    4. 2
    5. 3
    6. none of the above

 

 

 

  1. The last statement of the following code tries to assign a value outside the vector’s bounds (100 is not an index of the vector called points). This will cause a syntax error.

 

vector<Point> points(10);

points[100] = cwin.get_mouse(“Click anywhere”);

 

    1. TRUE
    2. FALSE

 

  1. How many “*” will be output by the following code fragment?

for (int i = 0; i < n; i++)

{

      for (int j = 0; j < m; j++)

      {

            cout << “*”;

      }

}

    1. 1
    2. m
    3. m + n
    4. m * n
    5. (m – 1) * (n – 1)
    6. none of the above