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 2 Question 69 Discussion

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

What happens when you attempt to compile and run the following code?

#include

#include

#include

using namespace std;

struct Even {

bool operator ()(int a) {

return (a % 2)==0?true:false;

}

};

int main () {

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

set s(t,t+15);

int number = count_if(s.begin(), s.end(), Even());

cout<< number<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Annice
2 hours ago
Ah, I see what's going on here. The set is created with 15 elements, but we're only checking the first 7. So the answer must be D) 8. Easy peasy!
upvoted 0 times
...
Rashida
1 days ago
Hmm, this looks like a tricky one. Let's see, we're using a custom 'Even' functor to count the even numbers in a set. I'm guessing the answer is C) 7, since the set contains 7 even numbers.
upvoted 0 times
...
Asha
3 days ago
I'm not sure, but I think the answer might be B) 3 because the Even struct might count the number 10 as even.
upvoted 0 times
...
Long
5 days ago
I agree with Buffy, the Even struct checks for even numbers and the set contains 4 even numbers.
upvoted 0 times
...
Buffy
16 days ago
I think the answer is A) 4 because the Even struct counts the even numbers in the set.
upvoted 0 times
...

Save Cancel