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 4 Question 88 Discussion

Actual exam question for C++ Institute's CPP - C++ Certified Professional Programmer exam
Question #: 88
Topic #: 4
[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:

Esteban
24 days ago
Ah, the joys of C++. Let me see here... transform, bind, add - yep, this is gonna be a doozy. I'm gonna go with D. Why? Because why not, that's why!
upvoted 0 times
Tabetha
6 days ago
I agree with the original user, D) 11 10 9 8 7 6 5 4 3 2
upvoted 0 times
...
Brigette
10 days ago
I'll choose C) 10 9 8 7 6 5 4 3 2 1
upvoted 0 times
...
Fatima
19 days ago
I'm going with B) 2 3 4 5 6 7 8 9 10 11
upvoted 0 times
...
Audria
20 days ago
I think it's A) 1 2 3 4 5 6 7 8 9 10
upvoted 0 times
...
...
Gail
1 months ago
I agree with Florencia, the correct answer is B.
upvoted 0 times
...
Florencia
1 months ago
But the code is adding 1 to each element, so it should be B.
upvoted 0 times
...
Jutta
1 months ago
I believe it's A.
upvoted 0 times
...
Dominga
1 months ago
Haha, this reminds me of that time I tried to debug a C++ program and ended up accidentally deleting the entire hard drive. Good times, good times. Anyway, I'm going with C for the output - reverse order seems like a classic C++ move.
upvoted 0 times
Paola
1 months ago
I agree, C does seem like a classic C++ move for the output.
upvoted 0 times
...
...
Keva
2 months ago
Woah, this looks like some complex C++ code! I'm going to go with the safe answer and say E - compilation error. I mean, who knows what kind of crazy stuff is going on in there, right?
upvoted 0 times
Rochell
5 days ago
Let's see, maybe it's not as tricky as it seems.
upvoted 0 times
...
Niesha
6 days ago
I think the answer might actually be A) 1 2 3 4 5 6 7 8 9 10.
upvoted 0 times
...
Adell
11 days ago
I agree, it's all about understanding the syntax and logic behind it.
upvoted 0 times
...
Shawnta
1 months ago
It's not that complex, just looks intimidating at first glance.
upvoted 0 times
...
...
Florencia
2 months ago
I think the answer is B.
upvoted 0 times
...
Viola
2 months ago
The output is definitely B. The transform function adds 1 to each element in v1 and stores the result in v2.
upvoted 0 times
Jennie
1 months ago
Yes, the transform function adds 1 to each element in v1.
upvoted 0 times
...
Carisa
1 months ago
I think the output is B.
upvoted 0 times
...
...