Q1. What happens when you attempt to compile and run the following code? #include #include using namespace std; template class A { T_v; public: A() {} A(T v): _v(v){} T getV() { return _v; } void add(T & a); void add(string & a); }; template void A::add(T & a) { _v+=a; } void A::add(string & a) { _v.insert(0, a); } int main() { Aa("Hello"); string s(" world!"); a.add(s); cout << a.getV() < return 0; }
A.program will display: Hello world!
B. compilation error
C. program will display: world!Hello
D. program will run without any output
Correct Answer: B
Q2. What happens when you attempt to compile and run the following code? #include #include #include using namespace std; void print(int v) { cout< struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return 10*(1+(start++ %3)); } }; int main() { vector v1(10); generate_n(v1.begin(), 10, Sequence(1)); remove(v1.begin(), v1.end(), 10); for_each(v1.begin(), v1.end(), print);cout< return 0; } Program outputs:
A.20 30 10 20 30 10 20 30 10 20
B. 20 30 20 30 20 30 20
C. 20 30 20 30 20 30 20 30 10 20
D. compilation error
Correct Answer: C
Q3. What happens when you attempt to compile and run the following code? #include #include using namespace std; template class A { T_v; public: A() {} A(T v): _v(v){} T getV() { return _v; } void add(T & a); void add(string & a); }; template void A::add(T & a) { _v+=a; } void A::add(string & a) { _v.insert(0, a); } int main() { Aa("Hello"); string s(" world!"); a.add(s); cout << a.getV() < return 0; }
A.program will display: Hello world!
B. compilation error
C. program will display: world!Hello
D. program will run without any output
Correct Answer: B
Q4. What happens when you attempt to compile and run the following code? #include #include #include #include using namespace std; class B { int val; public: B(int v=0):val(v){} int getV() const {return val;} operator int () const { return val;} }; ostream & operator <<(ostream & out, const B & v) { out< templatestruct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { B t[]={3,2,4,1,5,6,10,8,7,9}; vector v1(t, t+10); transform(v1.begin(), v1.end(), v1.begin(), bind2nd(plus(), 1)); for_each(v1.rbegin(), v1.rend(), Out(cout));cout< return 0; } Program outputs:
A.3 2 4 1 5 6 10 8 7 9
B. 4 3 5 2 6 7 11 9 8 10
C. 9 7 8 10 6 5 1 4 2 3
D. 10 8 9 11 7 6 2 5 3 4
E. compilation error
Correct Answer: E
$ 39
Reviews
There are no reviews yet.