Weekend Sale - Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: sntaclus

What happens when you attempt to compile and run the following code?

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

template struct Sequence {

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 v1; v1.assign(t, t+10);

stable_sort(v1.begin(), v1.end(), Less);

for_each(v1.begin(), v1.end(), Out(cout));cout<

return 0;

}

Program outputs:

A.

1.66 1.32 1.96 1.13 2.28 2.3 2.98 2.62 3.94 3.64

B.

1.13 1.32 1.66 1.96 2.28 2.3 2.62 2.98 3.64 3.94

C.

compilation error

D.

3.94 3.64 2.98 2.62 2.3 2.28 1.96 1.66 1.32 1.13

E.

the exact output is impossible to determine

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;

}

A.

program outputs: Found at position: 5

B.

program outputs: Found at position: 0

C.

program outputs: Found at position: 7

D.

compilation error

E.

program outputs: Found at position: 10

***/

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++;

}

}

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;

}

A.

compilation error

B.

runtime exception

C.

program outputs: 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2

D.

program outputs: 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2

E.

program outputs: 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1

What happens when you attempt to compile and run the following code?

#include

#include

#include

#include

#include

using namespace std;

templatestruct Out {

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 v1(5);

generate(v1.begin(), v1.end(), Sequence(1));

set s1(v1.rbegin(), v1.rend());

deque d1(s1.rbegin(), s1.rend());

reverse(v1.begin(),v1.end());

reverse(s1.begin(), s1.end());

reverse(d1.begin(), d1.end());

for_each(v1.begin(), v1.end(), Out(cout) );

for_each(s1.begin(), s1.end(), Out(cout) );

for_each(d1.begin(), d1.end(), Out(cout) );cout<

return 0;

}

Program outputs:

A.

5 4 3 2 1 1 2 3 4 5 1 2 3 4 5

B.

1 2 3 4 5 1 2 3 4 5 5 4 3 2 1

C.

no output

D.

1 2 3 4 5 5 4 3 2 1 1 2 3 4 5

E.

compilation error

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

templatestruct Out {

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:

A.

1 2 3 4 5 6 8 0 0 0

B.

3 4 0 0 0 0 0 0 0 0

C.

6 8 0 0 0 0 0 0 0 0

D.

compilation error

E.

1 2 5 0 0 0 0 0 0 0

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)

{

cout<

}

int main()

{

int a = 1;

g(a);

return 0;

}

A.

program displays: 1

B.

program displays: 2

C.

compilation error

D.

runtime exception

Which keywords can be used to define template type parameters? Choose all possible answers:

A.

class

B.

typedef

C.

typename

D.

static

E.

volatile

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 v1(10);

fill(v1.begin(), v1.end(), sequence(1,1));

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:

A.

1 2 3 4 5 6 7 8 9 10

B.

10

C.

0 0 0 0 0 0 0 0 0 0

D.

compilation error

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 s1(t, t+10);

vector v1(s1.rbegin(), s1.rend());

swap(s1, v1);

for_each(v1.begin(), v1.end(), myfunction);

for_each(s1.begin(), s1.end(), myfunction);

return 0;

}

Program outputs:

A.

10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10

B.

compilation error

C.

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

D.

10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1

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;}

};

templatestruct Out {

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 v1(10);

generate_n(v1.begin(), 10, Sequence(1));

for_each(v1.begin(), remove_if(v1.begin(), v1.end(), predicate), Out(cout));cout<

return 0;}

Program outputs:

A.

1 3 5 7 9 6 7 8 9 10

B.

1 3 5 7 9

C.

2 4 6 8 10

D.

compilation error

E.

no output