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 exam
Question #: 90
Topic #: 9
[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() {

int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

deque d1(t, t+10);

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

set s1(t,t+10);

cout<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Naomi
2 days ago
I'm going to go with option B. It just makes the most sense to me. Although, if I'm being honest, I'm half-hoping for a compilation error, just to make things more interesting. That would really spice up my day!
upvoted 0 times
...
Jonell
5 days ago
This is a good one! I bet the `deque` search returns 0 because the elements aren't sorted in the same order as the `set`. Gotta love those tricky data structure questions!
upvoted 0 times
...
Major
7 days ago
Wait, is this a trick question? The `binary_search` function returns 1 for true and 0 for false, so the output should be 1 1, right? Unless there's some hidden gotcha here...
upvoted 0 times
...
Martin
9 days ago
Hmm, looks like the program is trying to use the `B` class in a `set` and a `deque`. I'm guessing the comparison operators are implemented correctly, so the output should be pretty straightforward.
upvoted 0 times
...
Vashti
17 days ago
I'm not sure, but I think the answer might be D because the first binary_search should return 0 since 4 is not in the set, but the second one should return 1 because 4 is in the deque.
upvoted 0 times
...
Raul
18 days ago
I agree with Jordan, the first binary_search should return 1 since 4 is in the set, but the second one should return 0 because 4 is not in the deque.
upvoted 0 times
...
Jordan
23 days ago
I think the answer is A because binary_search returns 1 if the element is found in the set, and 0 if not.
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