View Assessment Result: Multiple Choice Quiz 8



Your performance was as follows:

1.
Access to ranges of elements in an STL container is typically handled by

(a) pointers
(b) suitable access member functions
(c) iterators
(d) references

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (c) No Feedback



2.

Consider the following statement using the STL remove routine.

      remove( a, b, x );

What of the following accurately describes what the variables a and b represent?



(a) references
(b) iterators
(c) pointers
(d) containers

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (b) No Feedback



3.

Consider the execution of the following.

      vector<int>  A(10,20);

Which of the following accurately describes what is created?



(a) An array of 10 arrays of ints, each of size 20
(b) An array of ints, indexed from 10 to 20
(c) An array of 10 ints, initializes to 20
(d) An array of 20 arrays of ints, each of size 10

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (c) No Feedback



4.

Consider the execution of the following.

   list<int>  A(10);

Which of the following accurately describes what is created?



(a) 10 linked list of ints, all initially empty.
(b) A linked list of 10 ints, with each element initially containing random values.
(c) An empty linked list of ints, but reserves memory for 10 entries.
(d) A linked list of 10 ints, with each element initially 0.

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (d) No Feedback



5.

Consider the following code fragment.

      stack<int>  S;
      S.push(123);
      S.push(456);

Now consider the following statement.

   cout << S.pop() << endl;

Which of the following most accurately describes what goes wrong when that statement is executed?



(a) pop() does not return a value.
(b) pop() requires an argument.
(c) An execution error occurs because an STL stack has no member function pop().
(d) An execution error occurs because pop() is a private member function.

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (a) No Feedback



6.

For an STL iterator it and an STL container A, the expression

      it != A.end()

is used for which of the following purposes?



(a) To test whether the iterator points at some element of A
(b) To test whether the iterator is at the one-past-the-end position
(c) To reset the iterator to the beginning of A
(d) To test whether the iterator points to the last element of A

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (b) No Feedback



7.

Consider the following code fragment.

      li    st<int>::const_iterator  it;
      for(  it = L.begin(); it != L.end(); ++it )
      *it = 0;

What is syntactically wrong with this fragment?



(a) Nothing
(b) The assignment using a const iterator
(c) The traversal using a const iterator
(d) The use of the prefix increment operator on a const iterator.

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (b) No Feedback



8.

Consider the following code fragment.

      list<int>::iterator  it;
      for(  it = L.end(); it != L.begin(); --it )
      cout << *it << endl;

Which of the following most accurately describes what is wrong with it?



(a) Linked lists in the STL are circular, so the loop will never terminate.
(b) There is no decrement operation for list iterators.
(c) It will cause an attempt to access a non-existing list element.
(d) The operator* cannot be used on an STL iterator.

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (c) No Feedback



9.
When using two iterators first and last to define a range of items in some container, which of the following is true concerning what they point to?

(a) It depends on the type of container.
(b) first points at the first item, and last at the last element.
(c) first points at the first item, and last at a position one past the last element.
(d) first points at a position one before the first item, and last at a position one past the last element.

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (c) No Feedback



10.

The STL contains a general purpose search function:

      find( first, last, x );

What search method does find use?



(a) Linear search
(b) Binary search
(c) It depends on whether the data are sorted.
(d) It depends on the type of container.

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 2.1.1 of the course notes.
   (a) No Feedback



Go to top of assessment.

Total score: 100.00