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 CPP Exam - Topic 3 Question 129 Discussion

Posted by Bettye on Sep 30, 2026 at 01:03 AM

Which sentence is correct about the code below?

#include

#include

#include

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; }

/* Insert Code Here */

};

struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } };

int main() {

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

vector v1(t, t + 10);

for_each(v1.begin(), v1.end(), add10());

vector::iterator it = find(v1.begin(), v1.end(), A(7));

cout << it?>getA() << endl;

return 0;

}

Suggested Answer: B

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
4 comments · newest first
MA
Marlon 3 days ago
I feel like the program might compile but could produce unexpected results if the comparison isn't set up correctly.
LE
Leana 8 days ago
I practiced a similar question where we had to implement comparison operators for a class. I think option D sounds right.
MA
Maira 13 days ago
I'm not entirely sure, but I think if the `operator !=` is not defined, it might lead to compilation issues.
AL
Alba 18 days ago
I remember that we discussed how the `find` function requires the `!=` operator to work properly with custom classes.
0/2000 characters

Save Cancel