View Assessment Result: Multiple Choice Quiz 8



Your performance was as follows:

1.

Execution of the code fragment

    list<int>  A(10);

does which of the following?



(a) Creates an empty linked list of ints, but reserves memory for 10 entries
(b) Creates a linked list of 10 ints, with each element initially containing random values.
(c) Creates 10 linked list of ints, all initially empty.
(d) Creates 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



2.

Consider the execution of the following.

    list<int>  A(10,20);

Which of the following accurately describes what is created?



(a) An array of size 20 of linked list, each containing 20 ints
(b) a linked list of 10 linked lists, each containing 20 ints
(c) A linked list of 10 ints, with each element initially 20
(d) A linked list of size 10, each containing 10 arrays of ints of size 20

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



3.

Execution of the code fragment

    stack<int,vector<int> >  S;

does which of the following?



(a) Creates a stack of integer vectors
(b) Creates a stack of ints, based on an integer vector
(c) Produces an execution error
(d) Creates a vector of integer stacks

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



4.

Execution of the code fragment

    stack<int,list<int> >  S;

does which of the following?



(a) Creates a stack of integer lists
(b) Creates a list of integer stacks
(c) Produces an execution error
(d) Creates a stack of ints, based on an integer list

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.

Suppose that both A and B are STL containers holding integers. Consider execution of the following code fragment.

 ostream_iterator  it( cout, " " );
 set_intersection( A.begin(), A.end(), B.begin(), B.end(), it );

Which of the following most accurately describes the results.



(a) Determines which integers are common to both containers, prints them out, and changes container B only so that, upon completion, A only holds the common elements.
(b) Determines which integers are common to both containers, and prints them out without changing the contents of the containers.
(c) Determines which integers are common to both containers, prints them out, and changes both containers so that, upon completion, the containers only hold the common elements.
(d) Determines which integers are common to both containers, prints them out, and changes container A only so that, upon completion, A only holds the common elements.

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



6.

For an STL iterator it, execution of the statement

    it--;

does which of the following?



(a) Decreases by 1 the size of the container pointed to by it.
(b) Steps the iterator backwards to the previous item.
(c) Post-decrements the item to which the iterator points.
(d) Pre-decrements the item to which the iterator points.

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.

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



8.

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 use of the prefix increment operator on a const iterator.
(d) The traversal using 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



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) first points at a position one before the first item, and last at a position one past the last element.
(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) It depends on the type of container.

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) It depends on the type of container.
(b) It depends on whether the data are sorted.
(c) Linear search
(d) Binary search

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



Go to top of assessment.

Total score: 100.00