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 109 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 109
Topic #: 9
[All CPP Questions]

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

ostream & operator <<(ostream & out, const B & v) { out<

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_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin());

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

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Shay
2 months ago
Whoa, they're playing around with all sorts of fancy C++ stuff here. I bet the output is gonna be a total surprise, like finding a unicorn in your cereal bowl.
upvoted 0 times
Dierdre
22 days ago
I'm not sure, but I think it might be option C) compilation error
upvoted 0 times
...
Dierdre
29 days ago
No way, I believe it will be option B) 1 2 3 4 5 6 7 8 9 10
upvoted 0 times
...
Dortha
30 days ago
C) compilation error
upvoted 0 times
...
Dortha
1 months ago
C) compilation error
upvoted 0 times
...
Dierdre
1 months ago
I think the output will be option A) 8 10 5 1 4 6 2 7 9 3
upvoted 0 times
...
...
Kristofer
2 months ago
Hmm, you might be right. Let's see what others think about this question.
upvoted 0 times
...
Joesph
2 months ago
I disagree, I believe the answer is B because set_symmetric_difference will give the symmetric difference between the two ranges.
upvoted 0 times
...
Kristofer
2 months ago
I think the answer is A because set_symmetric_difference will give the elements that are in one of the ranges but not in both.
upvoted 0 times
...
Bonita
2 months ago
Wait, did they just try to use a vector with a custom class? Sounds like a recipe for a good ol' fashioned compilation error to me.
upvoted 0 times
...
Denise
2 months ago
Oh man, this code looks like a real head-scratcher! I bet the compiler is gonna choke on it like a cat with a hairball.
upvoted 0 times
Ressie
20 days ago
Yeah, the code seems to be missing the necessary include for set_symmetric_difference.
upvoted 0 times
...
Ressie
30 days ago
I think the issue might be with the set_symmetric_difference function.
upvoted 0 times
...
Ressie
1 months ago
It will output: C) compilation error
upvoted 0 times
...
...