What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3<enter>? #include <iostream> 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): A
What happens when you attempt to compile and run the following code? #include <iostream> #include <map> #include <vector> #include <string> using namespace std; int main(){ int second[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 }; string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"}; map<int,string> m; for(int i=0; i<10; i++) { m.insert(pair<int,string>(second[i],first[i])); } m[0]="ten"; m.insert(pair<int,string>(1,"eleven")); for(map<int, string>::iterator i=m.begin();i!= m.end(); i++) { cout<<i?>second<<" "; } return 0; }
Answer(s): B
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3<enter>? #include <iostream> #include <string> #include <sstream> using namespace std; int main () { string s; getline(cin, s); stringstream input(s); stringstream output; for( ; !input.fail() ; ) { int i; input>>i; output<<hex<<i<<" "; } cout<<output.str(); return 0; }Program will output:
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> using namespace std; struct Compare { bool operator ()(int a) { if (a >5) return true; return false; } }; 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(), Compare()); cout<< number<<endl; return 0; }Program outputs:
Answer(s): E
What happens when you attempt to compile and run the following code? #include <deque> #include <set> #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()); set<B> s1(t,t+10); cout<<binary_search(s1.begin(),s1.end(), 4)<<" "<<binary_search(d1.begin(),d1.end(), 4)<<endl; 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.