What happens when you attempt to compile and run the following code? #include <list> #include <iostream> using namespace std; template<class T> void print(T start, T end) { while (start != end) { std::cout << *start << " "; start++; } } int main() { int t1[] = { 1, 7, 8, 4, 5 }; list<int> l1(t1, t1 + 5); int t2[] = { 3, 2, 6, 9, 0 }; list<int> l2(t2, t2 + 5); l1.sort(); list<int>::iterator it = l2.begin(); it++; it++; l1.splice(l1.end(),l2, it, l2.end()); print(l1.begin(), l1.end()); cout<<"Size:"<<l1.size()<<" "; print(l2.begin(), l2.end()); cout<<"Size:"<<l2.size()<<endl; return 0; }
Answer(s): A
What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> #include <algorithm> using namespace std; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator()(const T & val ) { out<<val<<" "; } }; struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return 10*(1+(start++ %3)); } }; int main() { vector<int> v1(10); vector<int> v2(10); generate(v1.begin(), v1.end(), Sequence(1)); sort(v1.rbegin(), v1.rend()); unique_copy(v1.begin(),v1.end(), v2.begin()); for_each(v2.begin(), v2.end(), Out<int>(cout) );cout<<endl; return 0; }Program outputs:
Answer(s): B
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <set> using namespace std; class A { int a; public: A(int a) : a(a) {} int getA() const { return a; } void setA(int a) { this?>a = a; } operator int() const {return a;} }; int main () { int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5}; set<A> s (t,t+15); cout<<equal(s.begin(), s.end(), t)<<endl; return 0; }Program outputs:
Answer(s): D
Which method added to class B at the marked spot will allow the code below to compile? Choose all possible solutions. #include <vector> #include <iostream> #include <algorithm> using namespace std; class B { int val; public: B(int v):val(v){} int getV() const {return val;} /* Insert Code Here */ }; ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; vector<B> v1(t, t+10); sort(v1.begin(), v1.end(), greater<B>()); for_each(v1.begin(), v1.end(), Out<B>(cout));cout<<endl; return 0; }
Answer(s): B,C,D
What happens when you attempt to compile and run the following code? #include <iostream> #include <map> #include <vector> #include <sstream> #include <string> using namespace std; int main(){ int t[] = { 3, 4, 2, 1, 0, 1, 2, 3, 4, 0 }; vector<int> v(t, t+10); multimap<int,string> m; for(vector<int>::iterator i=v.begin(); i!=v.end(); i++) { stringstream s; s<<*i<<*i; m.insert(pair<int,string>(*i,s.str())); } for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++) { cout<<*i<<" "; } return 0; }
Answer(s): E
Post your Comments and Discuss C++ Institute CPP exam prep with other Community members:
Our website is free, but we have to fight against AI bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the CPP content, but please register or login to continue.