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< template T start; T step; Sequence(T start, T step):start(start), step(step){} T operator()() { T v = start; start+=step; return v; } }; bool Less(float a, float b) { return int(a) int main() { float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13}; vector stable_sort(v1.begin(), v1.end(), Less); 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;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
bool operator==(A & b) { return a == b.a; }
};
struct Compare{
bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};
};
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector v (t,t+10);
vector::iterator it;
A m1[] = {A(1), A(2), A(3)};
it = find_end (v.begin(), v.end(), m1, m1+3, Compare());
cout << "Found at position: " << it?v.begin() << endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
class A {
int a;
public:
A(int a):a(a){}
operator int () const { return a;}int getA() const { return a;}
};
int main() {
int t1[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
list l1(t1, t1 + 10);
list l2(l1);
l2.reverse(); l1.splice(l1.end(),l2);
l1.pop_back();l1.unique();
print(l1.begin(), l1.end()); cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#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(v1.begin(), v1.end(), Sequence(1)); set deque reverse(v1.begin(),v1.end()); reverse(s1.begin(), s1.end()); reverse(d1.begin(), d1.end()); for_each(v1.begin(), v1.end(), Out for_each(s1.begin(), s1.end(), Out for_each(d1.begin(), d1.end(), Out 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 template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< 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< return 0; } Program outputs:
What happens when you attempt to compile and run the following code?
#include
using namespace std;
template
void g(int a)
{
cout< } template void g(A a) {
Which keywords can be used to define template type parameters? Choose all possible answers:
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;
}
struct sequence {
int val,inc;
sequence(int s, int i):val(s),inc(i){}
int operator()(){
int r = val; val += inc;
return r;
}
};
int main() {
vector
fill(v1.begin(), v1.end(), sequence(1,1));
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
#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
#include
using namespace std;
class B {
int val;
public:
B(int v):val(v){}
operator int() { return val;}
};
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++; } }; bool predicate(int v) { return v%2==0; } int main() { vector generate_n(v1.begin(), 10, Sequence(1)); for_each(v1.begin(), remove_if(v1.begin(), v1.end(), predicate), Out return 0;} Program outputs: