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 8 Question 68 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 68
Topic #: 8
[All CPP 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):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 t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

B t1[]={B(1),B(2),B(3),B(4)};

deque d1(t, t+10);

set s1(t, t+10);

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

cout<

<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Casie
18 days ago
I'm just going to close my eyes and randomly pick an answer. It's probably the only way I'll get this right. Maybe I should've brought a magic 8-ball with me to the exam.
upvoted 0 times
Adelina
2 days ago
Just take a guess, it's worth a shot.
upvoted 0 times
...
...
Antonio
1 months ago
This question is definitely not for the faint of heart. I'm going to have to think carefully about this one. Maybe I should've taken that 'Introduction to C++ Containers' course after all.
upvoted 0 times
Mindy
18 days ago
User 1
upvoted 0 times
...
...
Bronwyn
1 months ago
Wait, what? I thought the 'includes' function was used to check for inclusion in a vector or set, not a deque. Oh well, I'll just guess 'D) 0 1' and see what happens.
upvoted 0 times
Johnetta
26 days ago
User 1
upvoted 0 times
...
...
Delmy
1 months ago
Hmm, this looks like a tricky one. I'm going to go with 'B) 1 1' and hope I got it right. If not, maybe I can blame it on the caffeine shortage in the test center.
upvoted 0 times
...
Soledad
2 months ago
But why do you think it's D)?
upvoted 0 times
...
Audry
2 months ago
I disagree, I believe the answer is D) 0 1.
upvoted 0 times
...
Soledad
2 months ago
I think the answer is B) 1 1.
upvoted 0 times
...
Cristy
2 months ago
But why do you think so?
upvoted 0 times
...
Isaiah
2 months ago
I disagree, I believe the answer is B) 1 1
upvoted 0 times
...
Oretha
2 months ago
The code should compile without any errors, and the output should be '1 1', as the 'includes' function checks if all elements in the second range (t1) are present in the first range (d1 and s1).
upvoted 0 times
Glory
20 days ago
The code compiles without errors and the output should be '1 1'.
upvoted 0 times
...
Glory
1 months ago
It should output '1 1' because the 'includes' function checks if all elements in the second range are present in the first range.
upvoted 0 times
...
Yvonne
1 months ago
So, the correct answer would be B) 1 1.
upvoted 0 times
...
Yvonne
1 months ago
It should output '1 1' because the 'includes' function checks if all elements in the second range are present in the first range.
upvoted 0 times
...
...
Cristy
2 months ago
I think the answer is A) 1 0
upvoted 0 times
...