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
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
#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;
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector
vector
cout<< it?v.begin()<<endl;
return 0;
}
Program outputs: