What happens when you attempt to compile and run the following code? #include <deque> #include <iostream> #include <algorithm> using namespace std; class B { int val; public: B(int v):val(v){} int getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; 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}; deque<B> d1(t, t+10); sort(d1.begin(), d1.end()); deque<B>::iterator it = upper_bound(d1.begin(), d1.end(), B(4)); for_each(it, d1.end(), Out<B>(cout)); cout<<endl; return 0; }Program outputs:
Answer(s): A
What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> #include <algorithm> using namespace std; class B { int val; public: B(int v):val(v){} int getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; 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() { B t1[]={3,2,4,1,5}; B t2[]={5,6,8,2,1}; vector<B> v1(10,0); sort(t1, t1+5); sort(t2, t2+5); set_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin()); for_each(v1.begin(), v1.end(), Out<B>(cout));cout<<endl; return 0; }Program outputs:
Answer(s): E
What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> #include <algorithm> #include <functional> using namespace std; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { int t[]={3,2,4,1,5,6,10,8,7,9}; vector<int> v1(t, t+10); for_each(v1.begin(), v1.end(), bind2nd(plus<int>(), 1)); for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl; return 0; }Program outputs:
Answer(s): C
What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> #include <algorithm> using namespace std; class B { int val; public: B(int v=0):val(v){} int getV() const {return val;} operator int () const { return val;} }; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; struct Add { B operator()(B & a, B & b) { return a+b; }}; int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; vector<B> v1(t, t+10); vector<B> v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind1st(1,Add())); for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl; return 0; }Program outputs:
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5}; vector<int> v (t,t+15); int number = count(v.begin(), v.end(), 2); cout<< number<<endl; return 0; }Program outputs:
Post your Comments and Discuss C++ Institute CPP exam prep with other Community members: