What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> #include <set> 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> v1(t, t + 15); set<int> s1(t, t + 15); pair<set<int>::iterator, vector<int>::iterator > resultSet = mismatch(s1.begin(), s1.end(), v1.begin()); cout<<*resultSet.first<<" "<<*resultSet.second<<endl; return 0; }Program outputs:
Answer(s): B
Which changes introduced independently will allow the code to compile and display 0 0 1 1 8 8 9 9 (choose all that apply)? #include <iostream> #include <set> #include <vector> using namespace std; class A { int a; public: A(int a):a(a){} int getA() const { return a;} /* Insert Code Here 1 */ }; /* Insert Code Here 2*/ int main(){ A t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 }; set<A> s(t, t+10); /* Replace Code Here 3 */ multiset<A> s1(s.begin(),s.end()); /* Replace Code Here 4 */ s1.insert(s.begin(),s.end()); s1.erase(s1.lower_bound(2),s1.upper_bound(7)); multiset<A>::iterator i=s1.begin(); /* Replace Code Here 5 */ for( ;i!= s1.end(); i++) { cout<<i?>getA()<<" "; } cout<<endl; return 0; }
Answer(s): A,B,D
What happens when you attempt to compile and run the following code? #include <deque> #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 t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque<int> d1(t, t+10); deque<int>::iterator it = lower_bound(d1.begin(), d1.end(), 4); for_each(it, d1.end(), Out<int>(cout));cout<<endl; return 0; }Program outputs:
Answer(s): A
What happens when you attempt to compile and run the following code? Choose all that apply. #include <iostream> #include <fstream> #include <string> #include <list> #include <algorithm> #include <iomanip> 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<<setw(3)<<hex<<val; } }; int main () { int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; fstream f("test.out", ios::trunc|ios::out); list<B> l(t, t+10); for_each(l.begin(), l.end(), Out<B>(f)); f.close(); f.open("test.out"); for( ; f.good() ; ) { int i; f>>i; cout<<i<<" "; } f.close(); return 0; }
Answer(s): A,B,C,E
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 t[]={3,2,4,1,5,10,9,7,8,6}; vector<B> v1(t,t+10); sort(v1.begin(), v1.end(), greater<B>()); cout<<*min_element(v1.begin(), v1.end()); return 0; }Program outputs:
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.