



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Name:
class B { public: B(); B(int nn); void f(); viod g(); private: int n; }; class D: public B { public: D(int nn, float dd); void h(); private: double d; };
(a) (3) How many private members does an object of class D have? (C)
A) 0 B) 4 C) 2 D) 1 E) 3
(b) (3) How many public members does an object of class D have? (E)
A) 3 B) 5 C) 2 D) 6 E) 4
(c) (3) Which of the following functions can be invoked by an object of class D? (D)
A) g() B) f() C) h() D) all of the above
(a) (5) What, if anything, is wrong with the following class template?
template
template
In the constructor instantiation, A::A() is wrong. It must be A
template
int main() { int y = 3, z; z = f(y); }
Every template argument specified in the template-argument-list must be used in the argument of function template.
#include
(a) (6)What is the difference between the iterators defined here:
vector
*p=0; // OK to change vec where p points p=vec.end(); // error: l-value specifies const object // can’t change p itself q=vec.end(); // OK to change q *q=0; // error: l-value specifies const object // can’t change vec where q points.
(b) (12) Suppose we are given an STL vector container named vec that holds values of type double. Explain what each of the following mean:
*(vec.end()-vec.size()); // (a)(2) *(vec.end()-1); // (b)(2) vec.back(); // (c)(2) *(vec.rend()-1); // (d)(2) *(vec.begin()+vec.size()-1); // (e)(2) *(vec.rbegin()); // (f)(2)
(a) and (d) evaluate to the first element of the container. (a) starts with an iterator past the end, then subtracts the number of elements from this iterator, which results in an iterator to the first element of the vector. (d) starts with an iterator in front of the first element, then moves one towards the rear resulting in an iterator to the first element of the vector. (b), (c), (e), and (f) evaluate to the last element of the container. (b) starts with an iterator past the end, and moves one towards the front. Dereferencing gives the last element. (c) returns the back element. (e) begins with an iterator to the first element, add one less than the size, giving an iterator to the last element. Derefer- encing gives the last element. Finally, in (f), rbegin() member returns an iterator to the last element (the beginning element in reverse traversal of the vector elements). Dereferencing gives the last element. (c) (5) For a vector, inserting or deleting invalidates iterators in positions after the in- sertion or deletion. What happens to the set (or map) container if we delete in the middle? Insertion does not affect iterators, and deletion only invalidates iterators to the re- moved item.