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:

Kaitlyn
8 days ago
Wait, wait, wait. Didn't we learn that count_if() counts the number of elements for which the predicate is true? So the answer should be B) 3. I hope I'm not missing something obvious here.
upvoted 0 times
...
Annice
9 days 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
10 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
12 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
14 days ago
I agree with Buffy, the Even struct checks for even numbers and the set contains 4 even numbers.
upvoted 0 times
...
Buffy
25 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
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