Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 9 Question 90 Discussion

Actual exam question for C++ Institute's CPP - C++ Certified Professional Programmer exam
Question #: 90
Topic #: 9
[All CPP - C++ Certified Professional Programmer Questions]

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<

templatestruct Out {

ostream & out;

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

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

template struct Add : public binary_function {

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:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Bulah
11 days ago
Haha, tell me about it. I bet the person who wrote this question is some kind of coding wizard. Good luck to the rest of us mere mortals!
upvoted 0 times
Floyd
4 days ago
I think the answer is B) 2 3 4 5 6 7 8 9 10 11
upvoted 0 times
...
...
Janine
17 days ago
Wait, what's all this vector and transform stuff? I thought this was supposed to be a C++ exam, not a math test!
upvoted 0 times
Micah
8 days ago
Don't worry, it's still a C++ exam, just showing practical applications.
upvoted 0 times
...
Alayna
10 days ago
Yeah, it's a way to show how C++ can be used for mathematical operations.
upvoted 0 times
...
Tenesha
12 days ago
It's using vectors and algorithms to perform operations on objects.
upvoted 0 times
...
...
Eva
24 days ago
I'm pretty sure the correct answer is E. There's got to be a compilation error in that code somewhere.
upvoted 0 times
...
Louisa
25 days ago
Ha! Looks like someone's trying to trick us. I bet the output is D - the elements in v2 are going to be 11 down to 2.
upvoted 0 times
...
Jani
29 days ago
Hmm, I'm not so sure. That reverse loop at the end makes me think the output might be C. Let's see what happens!
upvoted 0 times
...
Kirk
1 months ago
I picked D because the elements in the vector are being added with 1 before being output.
upvoted 0 times
...
Cherry
1 months ago
I chose B because the code is adding 1 to each element in the vector.
upvoted 0 times
...
Rhea
1 months ago
I think the output is going to be B. The transform function is adding 1 to each element in v1, so the resulting elements in v2 should be 2 through 11.
upvoted 0 times
Alex
24 days ago
User 2
upvoted 0 times
...
Camellia
25 days ago
User 1
upvoted 0 times
...
...
Gracia
1 months ago
I'm not sure, but I think the answer might be E.
upvoted 0 times
...
Kirk
1 months ago
I disagree, I believe the answer is D.
upvoted 0 times
...
Cherry
2 months ago
I think the answer is B.
upvoted 0 times
...
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77