What happens when you attempt to compile and run the following code?
#include
#include
#include
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 number = count(v.begin(), v.end(), Compare());
cout<< number<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
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
sort(t1, t1+5);
sort(t2, t2+5);
merge(t1,t1+5,t2,t2+5,v1.begin());
for_each(v1.begin(), v1.end(), Out
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
using namespace std;
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
friend ostream & operator<<(ostream & c, const A
};
template
ostream & operator<<(ostream & c, const A
c<<v._v;return c; }
int main()
{
A
cout<<a<<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
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 ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { B t1[]={3,2,4,1,5}; int t2[]={5,6,8,2,1}; vector v1(10,0); 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(cout));cout<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#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;} };
ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
struct Add {
B operator()(B & a, B & b) { return a+b; } };
int main() {
B 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<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.unsetf(ios::hex);
cout<<100<<" ";
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#include
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)};
vectorv1(t, t+10);
dequed1(v1.begin(), v1.end());
d1.clear();
v1.clear();
cout<<A::c<< endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
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
deque
set
for_each(v1.begin(), v1.end(), display); //Line I
for_each(d1.begin(), d1.end(), *(new display())); // Line II
for_each(s1.begin(), s1.end(), display()); // Line III
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
deque
set
for_each(v1.begin(), v1.end(), myfunction); // Line I
for_each(d1.begin(), d1.end(), myfunction); // Line II
for_each(s1.begin(), s1.end(), myfunction); // Line III
return 0;
}
Which sentence is correct about the code below? Choose all that apply.
#include
#include
#include
using namespace std;
class F {
int val;
public:
F(int v):val(v){}
bool operator() (int v) {
if (v == val) return true;
return false;
}
};
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
if (find(v1.begin(), v1.end(), 6) == find(v1.begin(), v1.end(), F(6))) {
cout<<"Found!\n";
} else {
cout<<"Not found!\n";
}
return 0;
}