What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 64 100<enter>? #include <iostream> #include <string> #include <sstream> #include <iomanip> using namespace std; int main () { string s; getline(cin, s); stringstream input(s); stringstream output; for( ; !input.fail() ; ) { int i; input>>hex>>i; output<<setw(4)<<i; } cout<<output.str(); return 0; } What will be the result assuming that user will enter following sequence: 64 100:
Answer(s): C
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 Add(int a, int b) { 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(), bind2nd(ptr_fun (Add),1)); for_each(v2.rbegin(), v2.rend(), Out<int>(cout));cout<<endl; return 0; }Program outputs:
Answer(s): D
What happens when you attempt to compile and run the following code? #include <vector> #include <set> #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 start++; } }; int main() { vector<int> v1(10); generate_n(v1.begin(), 10, Sequence(1)); random_shuffle(v1.rbegin(), v1.rend()); sort(v1.begin(), v1.end(), great<int>()); for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl; return 0; }Program outputs:
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <map> using namespace std; void myfunction(pair<int, int> i) { cout << " " << i.first; } 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]; } for_each(m.begin(), m.end(), myfunction); return 0; }Program outputs:
Answer(s): B
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { cout<<true<<" "<<boolalpha<<false; return 0; } Program outputs:
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.