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:

Asha
1 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
3 days ago
I agree with Buffy, the Even struct checks for even numbers and the set contains 4 even numbers.
upvoted 0 times
...
Buffy
15 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