What happens when you attempt to compile and run the following code?
#include
#include <iostream>
#include <algorithm>
#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 t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; B t1[]={B(1),B(2),B(3),B(4)}; deque d1(t, t+10); set s1(t, t+10); sort(d1.begin(), d1.end()); cout<<includes(d1.begin(),d1.end(), t1,t1+4)<<" "< <<endl; return 0; } Program outputs:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: true true<enter>?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
bool a,b;
cin>>a>>b;
cout<<a<
return 0;
}
Program will output:
What happens when you attempt to compile and run the following code?
#include
#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 template 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 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(cout));cout<<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#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)};
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 <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
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
B t1[]={1,2,3,4,5,6,7,8,9,10};
B t2[]={1,2,3,4,5,6,7,8,9,10};
vector v1(t1, t1+10);
vector v2(t2, t2+10);
vector v3(10);
transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());
for_each(v3.rbegin(), v3.rend(), Out(cout));cout<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#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; }
};
struct Even {
bool operator ()(const A & a, const A &b) {
return (a.getA() % 2)==b.getA() % 2;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
deque
deque
cout<< it?d.begin()<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include <iostream>
#include <algorithm>
#include
using namespace std;
template
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
set
sort(d1.begin(), d1.end());
cout<<includes(s1.begin(),s1.end(), t1,t1+4)<<" "< <<endl; return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include <iostream>
using namespace std;
class A
{
int a;
public:
A():a(0){} A(int a){ this?>a = a;}
void setA(int a) {this?>a = a;}
int getA() {return a;}
};
ostream &operator<<(ostream & cout, A & a)
{
cout<< a.getA();
return cout;
}
int main ()
{
vectorv(5, new A());
v.push_back(new A(1));
vector::iterator it;
for(it = v.begin(); it != v.end(); it++)
{
cout<<*it<<" ";
}
cout<<endl;
return 0;
}
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:
Which are NOT valid instantiations of priority_queue object:
#include <iostream>
#include
#include
#include
#include
using namespace std;
int main()
{
deque
priority_queue
priority_queue
priority_queue
priority_queue
priority_queue
return 0;
}
PDF + Testing Engine
|
---|
$57.75 |
Testing Engine
|
---|
$43.75 |
PDF (Q&A)
|
---|
$36.75 |
C++ Institute Free Exams |
---|
![]() |