MoreExam
1. Question Content...
EXPLANATION
Answer: X - EXPLANATION Content.
Question1: 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() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; vector<B> v1(t, t+10); sort(v1.begin(), v1.end()); for_each(v1.begin(), v1.end(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question2: What will happen when you attempt to compile and run the following code?#include <iostream>#include <set>#include <vector>using namespace std;int main(){int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };vector<int>v(t, t+10);set<int> s1(v.begin(),v.end());s1.insert(v.begin(),v.end());bool found = s1.find(7);if (found){cout<<"Element found!\n";}else {cout<<"Element not found!\n";}return 0;}
Question3: What happens when you attempt to compile and run the following code?#include <iostream>#include <set>#include <list>using namespace std;int main(){int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };list<int>v(t, t+10);set<int> s1(v.begin(),v.end());if (s1.count(3) == 2) {s1.erase(3);}for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {cout<<*i<<" ";}return 0;}
Question4: 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:
Question5: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>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> v (t,t+15);int number = count(v.begin(), v.end(), 2);cout<< number<<endl;return 0;}Program outputs:
Question6: What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: true false<enter>?#include <iostream>#include <string>using namespace std;int main (){bool a,b;cin>>boolalpha>>a>>b;cout<<a<<b<<endl;return 0;}Program will output:
Question7: What happens when you attempt to compile and run the following code?#include <iostream>#include <set>#include <list>using namespace std;int main(){int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };list<int>v(t, t+10);multiset<int> s1(v.begin(),v.end());if (s1.count(3) == 2) {s1.erase(3);}for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++) {cout<<*i<<" ";}return 0;}
Question8: What happens when you attempt to compile and run the following code? Choose all possible answers.#include <iostream>using namespace std;class C {public:int _c;C():_c(0){}C(int c) { _c = c;}C operator+=(C & b) {C tmp; tmp._c = _c+b._c;return tmp;} };ostream & operator<<(ostream & c, const C & v) {c<<v._c; return c; }template <class T>class A {T _v;public:A() {}A(T v): _v(v){}T getV() { return _v; }void add(T & a) { _v+=a; }};int main(){A<int> b(2);A<C> a (5);a.add(C());cout << a.getV() <<endl;return 0;}
Question9: What happens when you attempt to compile and run the following code?#include <vector>#include <set>#include <iostream>#include <algorithm>using namespace std;class B {int val;public:B(int v):val(v){}operator int() { return val;}};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++; } };bool predicate(int v) { return v%2==0; }int main() {vector<int> v1(10);generate_n(v1.begin(), 10, Sequence(1));for_each(v1.begin(), remove_if(v1.begin(), v1.end(), predicate), Out<int>(cout));cout<<endl; return 0;} Program outputs:
Question10: What happens when you attempt to compile and run the following code?#include <deque>#include <list>#include <iostream>using namespace std;int main (){list<int>l1;deque<int>d1;for(int i=0; i<5; i++){l1.push_back(i);l1.push_front(i);d1.push_back(i);d1.push_front(i);}for(int i=0; i<d1.size(); i++){cout<<d1[i]<<" "<<l1[i]<<" ";}cout<<endl;return 0;}
Question11: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;int main(){cout.setf(ios::hex, ios::basefield);cout<<100<<" ";cout.flags(ios::showbase);cout<<100<<" ";return 0;}Program outputs:
Question12: 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=0):val(v){}int getV() const {return 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 t1[]={3,2,4,1,5}; B t2[]={6,10,8,7,9}; vector<B> v1(5); transform(t1,t1+5,t2,v1.rbegin(), plus<B>()); for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl; return 0;}Program outputs:
Question13: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>#include <functional>using namespace std;class B { int val;public:B(int v=0):val(v){}int getV() const {return val;}B operator +(const B &b )const { return B(val + b.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<<" "; } }; template<typename A> struct Add : public binary_function<A, A, A> { A operator() (const A & a, const A & b) const { return a+b; }}; int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; vector<B> v1(t, t+10); vector<B> v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add<B>()), 1)); for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question14: 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[]={3,2,4,1,5};int t2[]={6,10,8,7,9};vector<int> v1(5);transform(t1,t1+5,t2,v1.rbegin(), plus<int>());for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question15: What happens when you attempt to compile and run the following code?#include <iostream>#include <iomanip>using namespace std;int main (){float f = 10.126;cout.unsetf(ios::floatfield);cout<<showpoint<<f<<fixed<<" "<<setprecision(2)<<f<<endl;return 0;}Program outputs:
Question16: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <set>using namespace std;struct Even {bool operator ()(int a) {return (a % 2)==0?true:false;}};int main () {int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};set<int> s(t,t+15);int number = count_if(s.begin(), s.end(), Even());cout<< number<<endl;return 0;}Program outputs:
Question17: 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 t[]={3,2,4,1,5,6,10,8,7,9};vector<int> v1(t, t+10);for_each(v1.begin(), v1.end(), bind1st(plus<int>(), 1));for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question18: 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:
Question19: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;template<int>void g(int a){cout<<a?1<<endl;}template<class A>void g(A a){cout<<a+1<<endl;}int main(){int a = 1;g(a);return 0;}
Question20: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>#include <functional>using namespace std;class B { int val;public:B(int v=0):val(v){}int getV() const {return val;}B operator +(const B &b )const { return B(val + b.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<<" "; } }; B Add(B a, B b) { return a+b; } int main() { int t[]={1,2,3,4,5,6,7,8,9,10}; vector<B> v1(t, t+10); vector<B> v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun(Add),1)); for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question21: 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:
Question22: What happens when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;int main (){int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};vector<int>v1(t, t+10);deque<int>d1(t, t+10);d1.empty();v1.empty();if (v1.isempty()){cout<<"I am empty ";}else{cout<<"I am not empty ";}cout<<v1.size()<<" "<<d1.size()<<endl;return 0;}
Question23: 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(), B(4))<<" "<<binary_search(d1.begin(),d1.end(), B(4))<<endl;return 0;}Program outputs:
Question24: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>using namespace std;void myfunction(int i) {cout << " " << i;}int main() {int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };vector<int> v1(t, t + 10);copy_backward(t, t+10, v1.rend());for_each(v1.begin(), v1.end(), myfunction);return 0;}Program outputs:
Question25: 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;}
Question26: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>using namespace std;int main () {int t[] = {1,2,3,3,5,1,2,4,4,5};vector<int> v (t,t+10);vector<int>::iterator it = v.begin();while ( (it = adjacent_find (it, v.end())) != v.end()) {cout<<it?v.begin()<<" ";it++;}cout<< endl;return 0;}
Question27: What will happen when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;class A{int a;public:A(int a) {this?>a = a; c++;}~A() { c??;}static int c;};int A::c(0);int main (){A t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8 , 9};vector<A>v1(t, t+10);deque<A>d1(v1.begin(), v1.end());deque<A> d2;d2 = d1;cout<<A::c<< endl;return 0;}How many objects of type A will be created:
Question28: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;void myfunction(int i) { cout << " " << i;}struct sequence {int val,inc;sequence(int s, int i):val(s),inc(i){}int operator()(){int r = val; val += inc;return r;}};int main() {vector<int> v1(10);fill(v1.begin(), v1.end(), sequence(1,1));for_each(v1.begin(), v1.end(), myfunction);return 0;}Program outputs:
Question29: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;template <class T>class A {T_v;public:A() {}A(T v): _v(v){}friend ostream & operator<<(ostream & c, const A<T> & v);};template <class T>ostream & operator<<(ostream & c, const A<T> & v) {c<<v._v;return c; }int main(){A<int>a(10);cout<<a<<endl;return 0;}
Question30: What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?#include <iostream>#include <fstream>#include <string>#include <list>#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 () {ifstream f("test.in");list<int> l;for( ; !f.fail() ; ) {int i;f>>i;l.push_back(i);}f.close();for_each(l.begin(), l.end(), Out<int>(cout));return 0;}Programwill output:
Question31: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>using namespace std;int main () {int t[] = {1,2,3,4,5,1,2,3,4,5};vector<int> v (t,t+10);vector<int>::iterator it;int m1[] = {1, 3, 2};it = find_first_of (v.begin(), v.end(), m1, m1+3);cout << "First found at position: " << it?v.begin() << endl;return 0;}
Question32: What happens when you attempt to compile and run the following code?#include <iostream>#include <deque>#include <list>#include <queue>#include <vector>using namespace std;class compare {bool reverse;public:compare(bool revparam = false){ reverse = revparam;}bool operator()(int lhs, int rhs) const{if (reverse)return (lhs > rhs);elsereturn (lhs < rhs);}};int main(){int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };priority_queue<int, deque<int> > first(myints, myints + 10);priority_queue<int, vector<int>, compare> second(myints, myints + 10,compare(false));while (first.size() > 0){cout << first.top() << " "; first.pop();}while (second.size() > 0) {cout << second.top() << " ";second.pop();}return 0;}
Question33: What happens when you attempt to compile and run the following code?#include <iostream>#include <set>#include <vector>using namespace std;int main(){int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };vector<int>v(myints, myints+10);set<int> s1(v.begin(),v.end());s1.insert(v.begin(),v.end());s1.erase(s1.lower_bound(2),s1.upper_bound(7));for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {cout<<*i<<" ";}return 0;}
Question34: What happens when you attempt to compile and run the following code?#include <iostream>#include <set>#include <vector>using namespace std;int main(){int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };vector<int>v(myints, myints+10);set<int> s1(v.begin(),v.end());set<int, greater<int> > s2(v.begin(), v.end());for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {cout<<*i<<" ";}for(set<int, greater<int> >::iterator i=s2.begin();i!= s2.end(); i++) { cout<<*i<<" ";}cout<<endl;return 0;}
Question35: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;template <typename T>class A {T _v;public:A() {}A(T v): _v(v){}T getV() { return _v; }void add(T a) { _v+=a; }template <class U>U get(U a) {return (U)(_v);}};int main(){A<int> a(1);a.add(10);cout.setf( ios::showpoint);cout << a.getV() << " " << a.get(1.0)<<endl;return 0;}
Question36: 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"}; map<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));map<A, string>::iterator i=m.begin(); /* Replace Code Here 4 */for( ;i!= m.end(); i++) {cout<<i?>second<<" ";}cout<<endl;return 0;}
Question37: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;void myfunction(int i) {cout << " " << i;}int main() {vector<int> v1(10,1);fill(v1.begin()+2, v1.end()?2,2);fill_n(v1.begin()+4,2,3);for_each(v1.begin(), v1.end(), myfunction);return 0;}Program outputs:
Question38: What happens when you attempt to compile and run the following code?#include <list>#include <iostream>using namespace std;template<class T>void print(T start, T end) {while (start != end) {std::cout << *start << " "; start++;}}int main(){int t1[] ={ 1, 7, 8, 4, 5 };list<int> l1(t1, t1 + 5);int t2[] ={ 3, 2, 6, 9, 0 };list<int> l2(t2, t2 + 5);l1.sort();list<int>::iterator it = l2.begin();it++; it++;l1.splice(l1.end(),l2, it, l2.end());print(l1.begin(), l1.end()); cout<<"Size:"<<l1.size()<<" ";print(l2.begin(), l2.end()); cout<<"Size:"<<l2.size()<<endl;return 0;}
Question39: What happens when you attempt to compile and run the following code?#include <deque>#include <iostream>#include <algorithm>#include <set>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};int t1[]={1,2,3,4};deque<int> d1(t, t+10);set<int> s1(t, t+10);sort(d1.begin(), d1.end());cout<<includes(s1.begin(),s1.end(), t1,t1+4)<<" "<<includes(d1.begin(),d1.end(), t1,t1+4)<<endl;return 0;}Program outputs:
Question40: What happens when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>#include <string>using namespace std;template<typename T>void print(T start, T end){while (start != end)cout<<*start++;}int main (){string t[] = {"one", "two" ,"three" ,"four", "five"};vector<string>v1(t, t+5);deque<string>d1(v1.rbegin(), v1.rend());d1.push_back("zero");print(d1[0].rbegin(),d1[0].rend());return 0;}
Question41: What happens when you attempt to compile and run the following code?#include <iostream>#include <deque>#include <list>#include <stack>#include <vector>using namespace std;int main(){deque<int> mydeck;list<int> mylist; vector<int> myvector;stack<int> first;stack<int> second(mydeck);stack<int> third(second);stack<int, list<int> > fourth(mylist);fourth.push(10);fourth.push(11);fourth.push(12);stack<int, vector<int> > fifth(myvector);fifth.push(10);fifth.push(11);fifth.push(12);while(!fifth.empty()){cout<<fifth.top()<<" ";fifth.pop();}while (!fourth.empty()){cout << fourth.front() << " ";fourth.pop();}return 0;}
Question42: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;void myfunction(int i) {cout << " " << i;}int main() {int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };set<int> s1(t, t+10);vector<int> v1(s1.rbegin(), s1.rend());swap(s1, v1);for_each(v1.begin(), v1.end(), myfunction);for_each(s1.begin(), s1.end(), myfunction);return 0;}Program outputs:
Question43: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;int main(){cout.setf(ios::hex, ios::basefield);cout<<100.33<<" ";cout.setf(ios::showbase);cout<<100.33<<" ";return 0;}Program outputs:
Question44: 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<<" "; } };bool Greater(int v1, int v2) { return v1<v2; }int main() {int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};vector<int> v1(t, t+10);sort(v1.begin(), v1.end(), Greater);for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question45: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>#include <functional>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<<val<<" "; } };int main() {B t[]={3,2,4,1,5,6,10,8,7,9};vector<B> v1(t, t+10);for_each(v1.begin(), v1.end(), bind1st(plus<B>(), 1));for_each(v1.rbegin(), v1.rend(), Out<B>(cout));cout<<endl;return 0;}Program outputs:
Question46: What happens when you attempt to compile and run the following code?#include <iostream>#include <map>using namespace std;int main() {int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"}; multimap<int, string> m; for (int i = 0; i < 10; i++) { m.push_back(pair<int, string>(t[i], s[i]));}for (multimap<int, string>::iterator i = m.begin(); i != m.end(); i++) { cout << i?>first << " ";}return 0;}
Question47: What happens when you attempt to compile and run the following code?#include <iostream>#include <deque>#include <list>#include <queue>#include <vector>using namespace std;int main(){int t[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};deque<int> mydeck(t, t+10);list<int> mylist(t,t+10);queue<int> first;queue<int> second(mydeck);queue<int> third(second);queue<int, list<int> > fourth(mylist);mylist.clear();third.clear();cout<<third.size()<< " "<<mydeck.size()<< endl;cout<<fourth.size()<< " "<<mylist.size()<<endl;return 0;}
Question48: 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);copy(t1,t1+5,v1.begin());copy(t2,t2+5,v1.begin()+5);merge(v1.begin(), v1.begin()+5,v1.end());for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question49: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>int main (){std::vector<int>v1;for(int i = 10; i>0; i??){v1.push_back(i);}std::vector<int>::iterator it = v1.begin();int sum = 0;while(it != v1.end()){sum+=it++;}std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<<sum <<std::endl;return 0;}
Question50: What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 4 quit<enter>?#include <iostream>#include <string>#include <list>#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 (){list<string> l;while(cin.good()){string s;cin>>s;if (s == "quit") break;l.push_back(s);}for_each(l.begin(), l.end(), Out<string>(cout));return 0;}Program will output:
Question51: 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:
Question52: 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<<" ";}};struct Sequence {int start;Sequence(int start):start(start){}int operator()() { return start++; } };int main() {vector<int> v1(10);vector<int> v2(10);generate(v1.begin(), v1.end(), Sequence(1));random(v1.begin(),v1.end());for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;return 0;}Program outputs:
Question53: 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:
Question54: What happens when you attempt to compile and run the following code?#include <list>#include <iostream>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;}};int main() {int t1[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};list<A> l1(t1, t1 + 10);list<A> l2(l1);l2.reverse(); l1.splice(l1.end(),l2);l1.pop_back();l1.unique();print(l1.begin(), l1.end()); cout<<endl;return 0;}
Question55: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;void g(int a){cout<<a?1<<endl;}template<class A>void g(A a){cout<<a+1<<endl;}int main(){int a = 1;g(a);return 0;}
Question56: What happens when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;int main (){int t[] = {1, 2 ,3 ,4 ,5};vector<int>v1(t, t+5);deque<int>d1;d1.assign(v1.end(), v1.begin());for(int i=0; i<d1.size(); i++){cout<<d1.at(i)<<" ";}cout<<endl;return 0;}
Question57: 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<<" "; }};struct Sequence {int start;Sequence(int start):start(start){}int operator()() { return start++; }};struct Odd { bool operator()(int v) { return v%2==0; } };int main() {vector<int> v1(10);vector<int> v2(10);generate(v1.begin(), v1.end(), Sequence(1));stable_partition(v1.begin(),v1.end(), Odd());for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;return 0;}Program outputs:
Question58: 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_union(t1,t1+5,t2,t2+5,v1.begin());for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question59: What happens when you attempt to compile and run the following code?#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}; set<B> s1(t, t+10); sort(s1.begin(), s1.end()); for_each(s1.begin(), s1.end(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question60: What happens when you attempt to compile and run the following code?#include <deque>#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[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20}; deque<B> d1(t, t+10); sort(d1.begin(), d1.end()); pair<deque<B> ::iterator, deque<B>::iterator > result = equal_range(d1.begin(), d1.end(), B(20)); for_each(result.first, result.second, Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question61: 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 t[]={3,2,4,1,5,10,9,7,8,6};vector<int> v1(t,t+10);cout<<*max_element(v1.begin(), v1.end());return 0;}Program outputs:
Question62: What happens when you attempt to compile and run the following code?#include <iostream>#include <map>#include <vector>#include <sstream>#include <string>using namespace std;int main(){int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };vector<int> v(t, t+10);map<int,string> m;for(vector<int>::iterator i=v.begin(); i!=v.end(); i++) {stringstream s; s<<*i<<*i; m.insert(pair<int,string>(*i,s.str()));}for(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {cout<<*i<<" ";}return 0;}
Question63: What happens when you attempt to compile and run the following code?#include <string>#include <list>#include <iostream>using namespace std;template<class T> void print(T start, T end) {while (start != end) {std::cout << *start << " "; start++;}}int main() {string t1[] ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};list<string> l1(t1, t1 + 10);list<string> l2(l1);l2.reverse(); l1.splice(l1.end(),l2);l1.unique();print(l1.begin(), l1.end()); cout<<endl;return 0;}
Question64: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;void myfunction(int i) {cout << " " << i;}bool classifier(int v) {return v%2==0;}int main() {int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };vector<int> v1(t, t+10);set<int> s1(t, t+10);replace(v1.begin(), v1.end(),classifier, 10);for_each(v1.begin(), v1.end(), myfunction);return 0;}Program outputs:
Question65: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>#include <functional>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<<val<<" "; } };struct Add : public binary_function<B, B, B> {B operator() (const B & a, const B & b) const {return a+b; } };int main() {B t[]={1,2,3,4,5,6,7,8,9,10};vector<B> v1(t, t+10);vector<B> v2(10);transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), 1));for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;return 0;}Program outputs:
Question66: What happens when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;int main (){int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};vector<int>v1(t, t+10);deque<int>d1(t, t+10);vector<int>::iterator it1 = v1.begin();deque<int>::iterator it2 = d1.begin();d1.erase(it2+5);it2 = d1.begin();cout<<*(it2+5)<<" ";v1.erase(it1+5);it1 = v1.begin();cout<<*(it1+5)<<endl;}
Question67: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>#include <string>using namespace std;template<class T>struct Out {ostream & out;Out(ostream & o): out(o){}void operator() (const T & val ) { out<<val<<" "; } };int main() {string t[]={"aaa","Aaa", "aAa","aaA","bbb","Bbb", "bBb", "bbB"};vector<string> v1(t, t+8);sort(v1.begin(), v1.end());for_each(v1.begin(), v1.end(), Out<string>(cout));cout<<endl;return 0;}Program outputs:
Question68: What happens when you attempt to compile and run the following code?#include <deque>#include <iostream>#include <algorithm>#include <set>using namespace std;template<class T>struct Out {ostream & out;Out(ostream & o): out(o){}void operator() (const T & val ) { out<<val<<" "; }};bool Compare(char a, char b) { return tolower(a) < tolower(b);}int main() {char s[]={"qwerty"};char t1[]={"ert"};char t2[]={"ERT"};sort(s, s+6);cout<<includes(s,s+6, t1,t1+3, Compare)<<" "<<includes(s,s+6, t2,t2+3, Compare)<<endl; return 0;}Program outputs:
Question69: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;int main(){cout.setf(ios::oct, ios::basefield);cout<<100<<" ";cout.setf(ios::showbase);cout<<100<<" ";return 0;}Program outputs:
Question70: What will happen when you attempt to compile and run the following code?#include <iostream>#include <set>#include <vector>using namespace std;int main(){int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };vector<int>v(t, t+10);set<int> s1(v.begin(),v.end());s1.insert(v.begin(),v.end());pair<set<int>::iterator,set<int>::iterator> range;range = s1.equal_range(6);cout<<*range.first<<" "<<*range.second<<endl;return 0;}The output will be:
Question71: 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 Ifor_each(d1.begin(), d1.end(), *(new display())); // Line IIfor_each(s1.begin(), s1.end(), display()); // Line IIIreturn 0;}
Question72: 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;}
Question73: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>using namespace std;class A {int a;public:A(int a) : a(a) {}int getA() const { return a; } void setA(int a) { this?>a = a; }bool operator==(A & b) { return a == b.a; }};struct Compare{bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};};int main () {int t[] = {1,2,3,4,5,1,2,3,4,5};vector<A> v (t,t+10);vector<A>::iterator it;A m1[] = {A(1), A(2), A(3)};it = find_end (v.begin(), v.end(), m1, m1+3, Compare());cout << "Found at position: " << it?v.begin() << endl;return 0;}
Question74: What will happen when you attempt to compile and run the following code?#include <iostream>#include <set>#include <vector>using namespace std;int main(){int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };set<int>s(myints, myints+10);multiset<int> s1(s.begin(),s.end());s1.insert(s.begin(),s.end());s1.erase(s1.lower_bound(2),s1.upper_bound(7));for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++) {cout<<*i<<" ";}return 0;}The output will be:
Question75: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>int main (){int t[]={1,2,3,4,5};std::vector<int>v1(t,t+5);std::vector<int>v2(v1);v1.resize(10);v2.reserve(10);std::vector<int>::iterator i = v1.begin();int ii = 0;while (i != v1.end()) { std::cout<<i[ii]<<" ";ii??;i++; }i = v2.begin();ii=0;while (i != v2.end()) { std::cout<<i[ii]<<" ";ii??;i++; }return 0;}
Question76: 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:
Question77: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>using namespace std;template<typename T>class B { T val;public:B(T v):val(v){}T getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; template<class T>ostream & operator <<(ostream & out, const B<T> & 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<<" "; } }; bool Less(const B<float> &a, const B<float> &b) { return int(a.getV())<int(b.getV());} int main() { float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13}; vector<B<float> > v1; v1.assign(t, t+10); stable_sort(v1.begin(), v1.end(), Less); for_each(v1.begin(), v1.end(), Out<B<float> >(cout));cout<<endl; return 0;}Program outputs:
Question78: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>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> v (t,t+15);vector<int>::iterator it = search_n(v.begin(), v.end(), 4, 2);cout<< it?v.begin()<<endl;return 0;}Program outputs:
Question79: What happens when you attempt to compile and run the following code?#include <list>#include <deque>#include <iostream>using namespace std;template<class T>void print(T start, T end) {while (start != end) {std::cout << *start << " "; start++;}}int main(){int t1[] ={ 1, 7, 8, 4, 5 };list<int> l1(t1, t1 + 5);int t2[] ={ 3, 2, 6, 9, 0 };deque<int> d1(t2, t2 + 5);l1.sort();d1.sort();l1.merge(d1);print(l1.begin(), l1.end());print(d1.begin(), d2.end()); cout<<endl;return 0;}
Question80: 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<<" ";}};struct Sequence {int start;Sequence(int start):start(start){}int operator()() { return start++; }};struct Odd { bool operator()(int v) { return v%2==0; }};int main() {vector<int> v1(10);generate(v1.begin(), v1.end(), Sequence(1));partition(v1.begin(),v1.end(), Odd());for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;return 0;}Choose all possible outputs:
Question81: What happens when you attempt to compile and run the following code? Choose all that apply.#include <vector>#include <iostream>using namespace std;int main (){vector<int>v1(10, 3);v1.push_back(3);cout<<v1.capacity()<<" "<< v1.size()<<endl;return 0;}
Question82: 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<<" "; } };struct Add {int operator()(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(), bind1st(Add(),1));for_each(v2.rbegin(), v2.rend(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question83: 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;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);cout<<find(v1.begin(), v1.end(), 6)<<" "<<find(d1.begin(), d1.end(), 6)<<" "<<find(s1.begin(), s1.end(),6);return 0;}
Question84: 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 t1[]={3,2,4,1,5}; B t2[]={5,6,8,2,1}; vector<B> v1(10,0); sort(t1, t1+5); sort(t2, t2+5); set_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin()); for_each(v1.begin(), v1.end(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question85: 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:
Question86: What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;int main(){cout<<100<<" ";cout.setf(ios::hex);cout<<100<<" ";return 0;}Program outputs:
Question87: What will happen when you attempt to compile and run the following code? Choose all that apply.#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;class A {int a;public:A(int a) : a(a) {}int getA() const { return a; } void setA(int a) { this?>a = a; }bool operator < (const A & b) const { return a<b.a;}};class F {A val;public:F(A & v):val(v){}bool operator() (A & v) {if (v.getA() == val.getA()) return true;return false;}};int main() {int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };vector<A> v1(t, t + 10);set<A> s1(t, t + 10);A a(6); F f(a);find_if(s1.begin(), s1.end(), f);if (find_if(v1.begin(), v1.end(), f) !=v1.end()) {cout<<"Found!\n";} else {cout<<"Not found!\n";}return 0;}
Question88: What happens when you attempt to compile and run the following code?#include <vector>using namespace std;int main (){std::vector<int>v1;v1.push_back(10);return 0;}
Question89: What will happen when you attempt to compile and run the following code?#include <iostream>using namespace std;class C {};template <class T>class A {T _v;public:A() {}A(T v): _v(v){}T getV() { return _v; }void add(T a) { _v+=a; }};int main(){A<int> b;A<C> a;a.add(C());cout << b.getV() <<endl;return 0;}
Question90: 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:
Question91: What happens when you attempt to compile and run the following code?#include <deque>#include <iostream>#include <algorithm>#include <set>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[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};B t1[]={B(1),B(2),B(3),B(4)};deque<B> d1(t, t+10);set<B> s1(t, t+10);sort(d1.begin(), d1.end());cout<<includes(d1.begin(),d1.end(), t1,t1+4)<<" "<<includes(s1.begin(),s1.end(), t1,t1+4)<<endl;return 0;}Program outputs:
Question92: What happens when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;template<typename T>int calculate(T start, T end){int s = 0;while (start != end)s+= *start; start++;return s;}int main (){int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};vector<int>v1(t, t+5);deque<int>d1(t+5, t+10);cout<<calculate(t,t+10)<<" ";cout<<calculate(v1.begin()+1,v1.end()?2)<<" ";cout<<calculate(d1.rbegin()+1,d1.rend()?2)<<" ";cout<<calculate(t[0],t[10])<<" ";cout<<endl;return 0;}
Question93: 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:
Question94: 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<<" "; } };template <typename T> struct Sequence {T start; T step;Sequence(T start, T step):start(start), step(step){}T operator()() { T v = start; start+=step; return v; } };bool Less(float a, float b) { return int(a)<int(b);}int main() {float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};vector<float> v1; v1.assign(t, t+10);stable_sort(v1.begin(), v1.end(), Less);for_each(v1.begin(), v1.end(), Out<float>(cout));cout<<endl;return 0;}Program outputs:
Question95: 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;}
Question96: 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 t1[]={3,2,4,1,5}; B t2[]={6,10,8,7,9}; vector<B> 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<B>(cout));cout<<endl; return 0;}Program outputs:
Question97: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>using namespace std;class A{int a,b;public:A & operator =(const A & c) { a = c.a; return *this;}A():a(0),b(0){}void setA(int a) {this?>a = a;} void setB(int b) {this?>b = b;}int getA() {return a;} int getB() {return b;}};int main (){vector<A> v;A a;a.setA(10); a.setB(11);v.push_back(a);A b = v.front(); v.pop_back();cout<<b.getB()<<" "<<b.getA()<<endl;return 0;}
Question98: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>int main (){std::vector<int>v1;for(int i = 0; i<10; i++) {v1.push_back(i); }v1.resize(4);std::vector<int>::iterator it = v1.end();v1.insert(v1.end()?1, 4);for(int i=0 ; i<= v1.size(); i++) {std::cout<<v1.at(i)+v1[i]<<" "; }std::cout<<std::endl; return 0;}
Question99: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <set>using namespace std;class A {int a;public:A(int a) : a(a) {}int getA() const { return a; } void setA(int a) { this?>a = a; }bool operator < (const A & b) const { return a<b.a;}};struct Compare {bool operator ()(A & a) {if (a.getA() < 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};set<A> d (t,t+15);int number = count_if(d.begin(), d.end(), Compare());cout<< number<<endl;return 0;}Program outputs:
Question100: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>using namespace std;int main () {int t[] = {1,2,3,4,5,1,2,3,5,4};vector<int> v (t,t+10);vector<int>::iterator it;int m1[] = {1, 3, 2};it = find_end (v.begin(), v.end(), m1, m1+3);if (it != v.end())cout << "Found at position: " << it?v.begin() << endl;return 0;}
Question101: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;void myfunction(int i) {cout << " " << i;}int main() {int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };set<int> s1(t, t+10);vector<int> v1(s1.rbegin(), s1.rend());swap_ranges(s1.begin(), s1.end(), v1.begin());for_each(v1.begin(), v1.end(), myfunction);for_each(s1.begin(), s1.end(), myfunction);return 0;}Program outputs:
Question102: 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:
Question103: What happens when you attempt to compile and run the following code?#include <deque>#include <iostream>#include <algorithm>using namespace std;class B { int val;public:B(int v):val(v){} B(){}int getV() const {return 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); deque<B>::iterator it = lower_bound(d1.begin(), d1.end(), 4); for_each(it, d1.end(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question104: What will happen when you attempt to compile and run the following code?#include <iostream>using namespace std;template <typedef T>class A {T_v;public:A(T v): _v(v){}T getV() { return _v; }};int main(){A<int> a(1);cout << a.getV() <<endl;return 0;}
Question105: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <deque>using namespace std;class A {int a;public:A(int a) : a(a) {}int getA() const { return a; } void setA(int a) { this?>a = a; }};int main () {int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};deque<int> d (t,t+15);int number = count(d.begin(), d.end(), 2);cout<< number<<endl;return 0;}Program outputs:
Question106: What happens when you attempt to compile and run the following code?#include <iostream>#include <map>#include <string>using namespace std;int main(){int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"}; map<int,string> m; for(int i=0; i<10; i++) { m.insert(pair<int,string>(second[i],first[i]));}if (m[11] == "eleven") {cout<<"eleven ";}for(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {cout<<i?>second<<" ";}cout<<m.size();return 0;}
Question107: What will happen when you attempt to compile and run the following code?#include <iostream>using namespace std;class C {public:int _c;C():_c(0){}C(int c) { _c = c;}C operator+=(C & b) {C tmp;tmp._c = _c+b._c;return tmp;}};template <class T>class A {T _v;public:A() {}A(T v): _v(v){}T getV() { return _v; }void add(T & a) { _v+=a; }};int main(){A<int> b(2);A<C> a (5);C c;a.add(c);cout << a.getV() <<endl;return 0;}
Question108: 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;void myfunction(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(), myfunction); // Line Ifor_each(d1.begin(), d1.end(), myfunction); // Line IIfor_each(s1.begin(), s1.end(), myfunction); // Line IIIreturn 0;}
Question109: What happens when you attempt to compile and run the following code?#include <deque>#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()); deque<B>::iterator it = upper_bound(d1.begin(), d1.end(), B(4)); for_each(it, d1.end(), Out<B>(cout)); cout<<endl; return 0;}Program outputs:
Question110: Which pieces of code inserted independently into places marked 1 and 2 will cause the program to compile and display: 0 1 2 3 4 5 6 7 8 9? Choose all that apply.#include <list>#include <iostream>using namespace std;class A { int a; public:A(int a){ this?>a=a;}//insert code here 1};//insert code here 2template<class T> void print(T start, T end) {while (start != end) {std::cout << *start << " "; start++;}}int main() {A t1[] ={ 1, 7, 8, 4, 5 };list<A> l1(t1, t1 + 5);A t2[] ={ 3, 2, 6, 9, 0 };list<A> l2(t2, t2 + 5);l1.sort();l2.sort();l1.merge(l2);print(l1.begin(), l1.end());print(l2.begin(), l2.end()); cout<<endl;return 0;}
Question111: What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end<enter>?#include <iostream>#include <string>#include <list>#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 (){list<int> l;for( ; !cin.bad() ; ){int i;cin>>i;l.push_back(i);}for_each(l.begin(), l.end(), Out<int>(cout));return 0;}Program will output:
Question112: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;void myfunction(int i) {cout << " " << i;}int main() {int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };vector<int> v1(t, t+10);set<int> s1(t, t+10);replace(v1.begin(), v1.end(), 1, 10);replace(s1.begin(), s1.end(), 1, 10);for_each(v1.begin(), v1.end(), myfunction);return 0;}Program outputs:
Question113: 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 t[]={3,2,4,1,5,6,10,8,7,9};vector<int> v1(t, t+10);for_each(v1.begin(), v1.end(), bind2nd(plus<int>(), 1));for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl;return 0;}Program outputs:
Question114: Which changes introduced independently will allow code to compile and display 0 1 8 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 };vector<A>v(t, t+10);set<A> s1(v.begin(),v.end());s1.insert(v.begin(),v.end());s1.erase(s1.lower_bound(2),s1.upper_bound(7));for(set<A>::iterator i=s1.begin();i!= s1.end(); i++) {cout<<i?>getA()<<" ";}cout<<endl;return 0;}
Question115: Given three files: class.h, class.cpp and main.cpp containing small C++ project, which sentences are TRUE if you attempt to compile and run the program? Assume that the whole compiling environment is properly set.// File: main.cpp#include <iostream>#include "class.h"using namespace std;int main(){A<int> a;cout << a.getV() << endl;return 0;}//File: class.h#ifndef _CLASS_#define _CLASS_template <class T>class A {T_v;public:A() {}A(T v);T getV();};#endif//File: class.cpp#include "class.h"template<typename T>A<T>::A(T v):_v(v) {}template<class T>T A<T>::getV() { return _v; }
Question116: What happens when you attempt to compile and run the following code?#include <iostream>#include <deque>#include <list>#include <queue>#include <vector>using namespace std;int main(){deque<int> mydeck;list<int> mylist; vector<int> myvector;queue<int> first; queue<int> second(mydeck);queue<int> third(second); queue<int, list<int> > fourth(mylist);fourth.push(10);fourth.push(11);fourth.push(12);queue<int, vector<int> > fifth(myvector);fifth.push(10);fifth.push(11);fifth.push(12); // Line Iwhile(!fifth.empty()){cout<<fifth.front()<<" "; // Line IIfifth.pop(); // Line III}while (!fourth.empty()){cout << fourth.front() << " ";fourth.pop(); // Line IV}return 0;}
Question117: What will happen when you attempt to compile and run the following code?#include <iostream>#include <iomanip>using namespace std;int main (){float f = 10.126;cout.unsetf(ios::floatfield);cout<<scientific<<f<<" "<<setprecision(3)<<f<<endl;return 0;}What will be a mantissa part of the numbers displayed:
Question118: 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;} }; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { B t1[]={3,2,4,1,5}; B t2[]={5,6,8,2,1}; vector<B> v1(10,0); 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<B>(cout));cout<<endl; return 0;}Program outputs:
Question119: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <set>using namespace std;class A {int a;public:A(int a) : a(a) {}int getA() const { return a; } void setA(int a) { this?>a = a; }operator int() const {return a;}};int main () {int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};set<A> s (t,t+15);cout<<equal(s.begin(), s.end(), t)<<endl;return 0;}Program outputs:
Question120: What happens when you attempt to compile and run the following code?#include <iostream>#include <algorithm>#include <vector>using namespace std;int main () {int t[] = {1,2,3,4,5,1,2,3,4,5};vector<int> v (t,t+10);vector<int>::iterator it;int m1[] = {1, 2, 3};it = search (v.begin(), v.end(), m1, m1+3);cout << "found at position: " << it?v.begin() << endl;return 0;}Program outputs:
Question121: 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<<" ";}};struct Sequence {int start;Sequence(int start):start(start){}int operator()() { return 10*(1+(start++ %3)); } };int main() {vector<int> v1(10);vector<int> v2(10);generate(v1.begin(), v1.end(), Sequence(1));sort(v1.rbegin(), v1.rend());unique_copy(v1.begin(),v1.end(), v2.begin());for_each(v2.begin(), v2.end(), Out<int>(cout) );cout<<endl;return 0;}Program outputs:
Question122: 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:
Question123: What will happen when you attempt to compile and run the following code?#include <iostream>using namespace std;template <class T>class A {T_v;public:A(T v);};template<class T>A::A(T v):_v(v) {}int main(){A<int> a(2);cout<<1<<endl;return 0;}
Question124: What will happen when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;int main (){vector<int>v1;deque<int>d1;for(int i=0; i<5; i++){v1.push_back(i);v1.push_front(i);d1.push_back(i);d1.push_front(i);}for(int i=0; i<d1.size(); i++){cout<<d1[i]<<" "<<v1[i]<<" ";}cout<<endl;return 0;}What will be its output:
Question125: 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 t1[]={3,2,4,1,5}; B t2[]={6,10,8,7,9}; vector<B> v1(10,0); sort(t1, t1+5); sort(t2, t2+5); copy(t1,t1+5,v1.begin()); copy(t2,t2+5,v1.begin()+5); inplace_merge(v1.begin(), v1.begin()+5,v1.end()); for_each(v1.begin(), v1.end(), Out<B>(cout));cout<<endl; return 0;}Program outputs:
Question126: What happens when you attempt to compile and run the following code?#include <deque>#include <iostream>#include <algorithm>#include <set>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);set<int> s1(t,t+10);cout<<binary_search(s1.begin(),s1.end(), 4)<<" "<<binary_search(d1.begin(),d1.end(), 4)<<endl; return 0;}Choose all possible outputs (all that apply):
Question127: What happens when you attempt to compile and run the following code?#include <iostream>#include <map>using namespace std;int main() {int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"}; multimap<int, string> m; for (int i = 0; i < 10; i++) { m.insert(pair<int, string>(t[i], s[i]));}if (m.count(3) == 2) {m.erase(3);}for (multimap<int, string>::iterator i = m.begin(); i != m.end(); i++) { cout << i?>first << " ";}return 0;}
Question128: What will happen when you attempt to compile and run the following code?#include <deque>#include <vector>#include <iostream>using namespace std;int main (){int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};deque<int>d1(t, t+10);vector<int>v1(t, t+10);cout<<v1.size()<<" "<<v1.capacity()<<" ";cout<<d1.size()<<" ";<<d1.capacity()<<" ";d1.resize(12); v1.resize(12);cout<<v1.size()<<" "<<v1.capacity()<<" ";cout<<d1.size()<<" ";<<d1.capacity()<<" ";d1.reserve(20);v1.reserve(20);cout<<v1.size()<<" "<<v1.capacity()<<" ";cout<<d1.size()<<" ";<<d1.capacity()<<endl;return 0;}
Question129: What happens when you attempt to compile and run the following code?#include <vector>#include <iostream>#include <algorithm>using namespace std;void print(int v) { cout<<v<<" "; }struct Sequence {int start;Sequence(int start):start(start){}int operator()() {return 10*(1+(start++ %3));}};int main() {vector<int> v1(10);generate_n(v1.begin(), 10, Sequence(1));remove(v1.begin(), v1.end(), 10);for_each(v1.begin(), v1.end(), print);cout<<endl;return 0;}Program outputs:
Question130: What happens when you attempt to compile and run the following code?#include <iostream>#include <map>using namespace std;int main() {int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"}; map<int, string> m; for (int i = 0; i < 10; i++) { m.push_back(pair<int, string>(t[i], s[i]));}for (map<int, string>::iterator i = m.begin(); i != m.end(); i++) {cout << i?>first << " ";}return 0;}
Question131: 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;}
Question132: 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:
Question133: What happens when you attempt to compile and run the following code? Choose all that apply.#include <deque>#include <vector>#include <iostream>using namespace std;class A{int a;public:A(int a) {this?>a = a; c++;}A(const A & a) {this?>a = a.a; c++;}~A() { c??;}static int c;};int A::c(0);int main (){A* t[] = {new A(1), new A(2), new A(3),new A(4), new A(5)};vector<A*>v1(t, t+10);deque<A*>d1(v1.begin(), v1.end());d1.clear();v1.clear();cout<<A::c<< endl;return 0;}
Question134: What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?#include <iostream>#include <fstream>#include <string>#include <list>#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[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};fstream f("test.out");list<int> l(t, t+10);for_each(l.begin(), l.end(), Out<int>(f));f.close();return 0;}
Question135: What happens when you attempt to compile and run the following code?#include <deque>#include <iostream>#include <algorithm>#include <set>using namespace std;template<class T>struct Out {ostream & out;Out(ostream & o): out(o){}void operator() (const T & val ) { out<<val<<" "; }};int main() {char s[]={"qwerty"};char t1[]={"ert"};char t2[]={"ERT"};sort(s, s+6);cout<<includes(s,s+6, t1,t1+3)<<" "<<includes(s,s+6, t2,t2+3)<<endl;return 0;}Program outputs:
Question136: What happens when you attempt to compile and run the following code?#include <iostream>#include <iomanip>using namespace std;int main (){float f = 10.126;cout<<f<<" "<<setprecision(2)<<f<<endl;return 0;}Program outputs: