What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return start++; } }; int main() { vector generate_n(v1.begin(), 10, Sequence(1)); random_shuffle(v1.rbegin(), v1.rend()); sort(v1.begin(), v1.end(), great for_each(v1.begin(), v1.end(), Out return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< int main() { int t1[]={3,2,4,1,5}; int t2[]={6,10,8,7,9}; vector transform(t1,t1+5,t2,v1.rbegin(), plus for_each(v1.rbegin(), v1.rend(), Out return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main(){
vector
multiset
for(int i=10; i>0; i??) {
v.push_back(i); s.push_back(i);
}
print(v.begin(), v.end()); print(s.begin(), s.end());cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque set cout< return 0; } Choose all possible outputs (all that apply):
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;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
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< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< template 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 v1(t, t+10); vector v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add()), 1)); for_each(v2.rbegin(), v2.rend(), Out(cout));cout< return 0; } Program outputs:
What will happen when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};
deque
vector
cout< cout< d1.resize(12); v1.resize(12); cout< cout< d1.reserve(20);v1.reserve(20); cout< cout< return 0; }
Which are NOT valid instantiations of priority_queue object:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
deque
priority_queue
priority_queue
priority_queue
priority_queue
priority_queue
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out< bool Greater(int v1, int v2) { return v1 int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; vector sort(v1.begin(), v1.end(), Greater); for_each(v1.begin(), v1.end(), Out return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
void print(int v) { cout< struct Sequence { int start; Sequence(int start):start(start){} int operator()() { return 10*(1+(start++ %3)); } }; int main() { vector generate_n(v1.begin(), 10, Sequence(1)); remove(v1.begin(), v1.end(), 10); for_each(v1.begin(), v1.end(), print);cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
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< return 0; }
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.33<<" ";
cout.setf(ios::showbase);
cout<<100.33<<" ";
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, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
list
multiset
if (s1.count(3) == 2) {
s1.erase(3);
}
for(multiset
cout<<*i<<" ";
}
return 0;
}
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< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
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 ()
{
vectorv;
A a;
a.setA(10); a.setB(11);
v.push_back(a);
A b = v.front(); v.pop_back();
cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
template
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 2, 3, 4, 5};
list
l1.remove(2);
print(l1.begin(), l1.end()); cout< return 0; }
What will happen when you attempt to compile and run the following code? Choose all possible answers.
#include
using namespace std;
class B {};
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
};
int main()
{
A
Ab;
a.add(10);
cout << a.getV() < return 0; }
What happens when you attempt to compile and run the following code?
#include
#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>v.val;} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20}; deque d1(t, t+10); sort(d1.begin(), d1.end(), greater()); pair for_each(result.first, result.second, Out(cout));cout< 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
#include
#include
using namespace std;
int main ()
{
bool a,b;
cin>>a>>b;
What happens when you attempt to compile and run the following code? Choose all possible answers.
#include
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< template class A { T_v; public: A() {} A(T v): _v(v){} T getV() { return _v; } void add(T & a) { _v+=a; } }; int main() { A A a.add(C()); cout << a.getV() < return 0; }
What happens when you attempt to compile and run the following code?
#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 };
set
vector
swap(s1, v1);
for_each(v1.begin(), v1.end(), myfunction);
for_each(s1.begin(), s1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#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
copy(t, t+10, v1.end());
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
template
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a) { _v+=a; }
void add(string & a) {
_v.insert(0, a);
}
};
int main()
{
A
string s(" world!");
a.add(s);
cout << a.getV() < return 0; }
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< int main() { int t[]={3,2,4,1,5,10,9,7,8,6}; vector cout<<*max_element(v1.begin(), v1.end()); 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< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20}; deque d1(t, t+10); sort(d1.begin(), d1.end()); pair for_each(result.first, result.second, Out(cout));cout< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
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
set
replace(v1.begin(), v1.end(),classifier, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
template
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 7, 8, 4, 5 };
list
int t2[] ={ 3, 2, 6, 9, 0 };
list
l1.sort();
list
it++; it++;
l1.splice(l1.end(),l2, it, l2.end());
print(l1.begin(), l1.end()); cout<<"Size:"< print(l2.begin(), l2.end()); cout<<"Size:"< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main(){
int t[] ={ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
list
set
if (s1.count(3) == 2) {
s1.erase(3);
}
for(set
cout<<*i<<" ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#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
set
pair
cout<<*resultSet.first<<" "<<*resultSet.second< return 0; } Program outputs:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three
#include
#include
using namespace std;
int main ()
{
string a;
cin>>a;
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map
for(int i=0; i < 10; i++) {
m[i]=t[i];
}
map
cout<
return 0;
}
Program outputs: