C++ Institute C++ Certified Professional Programmer CPP Question # 56 Topic 6 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 56 Topic 6 Discussion

CPP Exam Topic 6 Question 56 Discussion:
Question #: 56
Topic #: 6

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

#include

#include

#include <algorithm>

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

};

struct Odd { bool operator()(int v) { return v%2==0; }};

int main() {

vector v1(10);

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

partition(v1.begin(),v1.end(), Odd());

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

return 0;

}

Choose all possible outputs:


A.

1 2 3 4 5 6 7 8 9 10


B.

5 7 3 9 1 10 2 8 4 6


C.

10 2 8 4 6 5 7 3 9 1


D.

4 6 8 10 2 7 5 3 1 9


E.

2 4 6 8 10 1 3 5 7 9


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.