What happens when you attempt to compile and run the following code? #include #include #include 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}; 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 d (t,t+15); int number = count_if(d.begin(), d.end(), Compare()); cout<< number<return 0; } Program outputs:
Correct Answer: E
Explanation:
Answer: E
Question 2
What happens when you attempt to compile and run the following code? #include #include #include using namespace std; templatestruct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<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 v1(t, t+10); vector v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind2nd(Add(),1)); for_each(v2.rbegin(), v2.rend(), Out(cout));cout<return 0; }Program outputs:
Correct Answer: E
Explanation:
Answer: E
Question 3
What happens when you attempt to compile and run the following code? Choose all that apply. #include #include #include #include #include #include using namespace std;class B { int val; public: B(int v=0):val(v){} int getV() const {return val;} operator int() const { return val; };}; templatestruct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) {out<int main () { int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; fstream f("test.out", ios::trunc|ios::out); list l(t, t+10); for_each(l.begin(), l.end(), Out(f)); f.close(); f.open("test.out"); for( ; f.good() ; ) { int i; f>>i; cout<} f.close(); return 0;
}
Correct Answer: A, B, C, E
Explanation:
Answer: A,B,C,E
Question 4
What happens when you attempt to compile and run the following code? #include #include #include using namespace std; int main () { int t[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; vector v1(t, t + 10); deque d1(v1.begin(), v1.end());deque d2; d2 = d1; d2.insert(d1.rbegin(), 10); for(int i = 0; i
Correct Answer: D
Explanation:
Answer: D
Demo Practice Mode
You are viewing only the questions marked as Demo.