Exam CPP Topic 9 Question 95 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 95
Topic #: 9
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
bool operator < (const A & b) const { return a<b.a;}
};
struct Compare {
bool operator ()(A & a) {
if (a.getA() < 5) return true;
return false;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
set<A> d (t,t+15);
int number = count_if(d.begin(), d.end(), Compare());
cout<< number<<endl;
return 0;
}
Program outputs:

Suggested Answer: B Vote an answer

by Anastasia at Jul 27, 2026, 05:42 PM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

0
0
0
10