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 t1[]={1,2,3,4,5,6,7,8,9,10}; int t2[]={1,2,3,4,5,6,7,8,9,10}; vector<int> v1(t1, t1+10); vector<int> v2(t2, t2+10); vector<int> v3(10); transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus<int>()); for_each(v3.rbegin(), v3.rend(), Out<int>(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> #include <functional> using namespace std; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; struct Add : public binary_function<int, int, int> { int operator() (const int & a, const int & b) const { return a+b; } }; int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; vector<int> v1(t, t+10); vector<int> v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), 1)); for_each(v2.rbegin(), v2.rend(), Out<int>(cout));cout<<endl; return 0; }Program outputs:
Answer(s): D
Which changes introduced independently will allow the code to compile and display “one” “eight” “nine” “ten”? Choose all that apply. #include <iostream> #include <map> #include <string> 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(){ int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 }; string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"}; multimap<A,string> m; /* Replace Code Here 3 */ for(int i=0; i<10; i++) { m.insert(pair<A,string>(A(t[i]),s[i])); } m.erase(m.lower_bound(2),m.upper_bound(7)); multimap<A, string>::iterator i=m.begin(); /* Replace Code Here 4 */ for( ; i!= m.end(); i++) { cout<<i?>second<<" "; } cout<<endl; return 0; }
Answer(s): A,B,D
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <map> using namespace std; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; map<int, int> m; for(int i=0; i < 10; i++) { m[i]=t[i]; } map<int, int>::iterator it = find(m.begin(), m.end(), 5); cout<<it?>first; return 0; }Program outputs:
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; 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<int> l(t, t+10); for_each(l.begin(), l.end(), Out<int>(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
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.