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<<" "; } }; int main() { int t1[]={3,2,4,1,5}; int t2[]={5,6,8,2,1}; vector<int> v1(10); sort(t1, t1+5); sort(t2, t2+5); set_difference(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.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 <list> #include <iostream> #include <deque> using namespace std; template<class T> void print(T start, T end) { while (start != end) { std::cout << *start << " "; start++; } } class A { int a; public: A(int a):a(a){} operator int () const { return a;} int getA() const { return a;} }; struct R { int val; R(int v):val(v){} bool operator ()(const A & a) { return a>val;} }; int main() { int t1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; list<A> l1(t1, t1 + 10); R r(4); l1.remove_if(r); print(l1.begin(), l1.end()); cout<<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<<" "; } }; int main() { int t1[]={3,2,4,1,5}; int t2[]={6,10,8,7,9}; vector<int> v1(10); sort(t1, t1+5); sort(t2, t2+5); merge(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl; return 0; }Program outputs:
Answer(s): D
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1.1 2.2 3.3<enter>? #include <iostream> #include <string> using namespace std; int main () { int a,b,c; cin>>a>>b>>c; cout<<a<<b<<c<<endl; return 0; }Program will output:
Answer(s): E
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> #include <deque> #include <set> using namespace std; struct display { void operator() (int i) {cout << " " << i;} }; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector<int> v1(t, t + 10); deque<int> d1(t, t + 10); set<int> s1(t, t + 10); for_each(v1.begin(), v1.end(), display); //Line I for_each(d1.begin(), d1.end(), *(new display())); // Line II for_each(s1.begin(), s1.end(), display()); // Line III return 0; }
Answer(s): C
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.