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 11 Question 119 Discussion

Posted by Kallie on Mar 02, 2026 at 05:50 AM

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

#include

#include

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

bool operator < ( const A & b) const { return a

};

struct display { void operator() (const A & a) {cout << " " << a.getA();} };

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

set s1(t, t + 10);

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

for_each(s1.begin(), s1.end(), add10()); for_each(s1.begin(), s1.end(), display());

return 0;

}

Suggested Answer: D

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
26 comments · newest first
RE
Ressie 1 month ago
I believe it should output C.
SH
Shaunna 2 months ago
Option B seems right to me.
XU
Xuan 2 months ago
I feel like there's a mistake in the code.
CH
Chantay 2 months ago
I think it will compile fine.
NA
Nathalie 2 months ago
No way, it's definitely option B. The add10 function works on the vector.
EM
Emmett 2 months ago
I believe it will output option C. The values will be updated.
LE
Leonor 2 months ago
I agree, the `this?>a` part seems wrong.
JO
Johnson 3 months ago
I think there's a compilation error. The syntax looks off.
BR
Brittani 3 months ago
I see a potential compilation error with "this?>a".
AJ
Aja 3 months ago
Option B seems right to me. Values increase by 10.
DA
Dana 3 months ago
I feel like there's a mistake in the code.
CR
Cristy 3 months ago
I think it will compile fine.
DI
Dick 3 months ago
The operator overloading is correct, but that typo is a killer!
LA
Lashawn 4 months ago
Nah, it should output the modified values after add10.
VE
Veronique 5 months ago
Wait, are you serious? I thought it would just run fine.
RO
Ronna 5 months ago
Definitely going with option D, that won't compile!
WI
Willodean 5 months ago
Looks like a compilation error due to the `this?>a` typo.
ST
Stephanie 6 months ago
The output should be option B if it runs correctly!
WI
Wilford 6 months ago
Wait, are you sure it won't compile?
XU
Xuan 6 months ago
I thought it would output the original numbers first, then the modified ones.
IL
Ilda 6 months ago
Totally agree, that syntax is wrong!
OR
Oretha 6 months ago
Looks like a compilation error due to the `this?>a` line.
DO
Doretha 6 months ago
I feel like the output should be option B, since we're adding 10 to each element in the vector, but I'm not completely confident about the set part.
GE
Genevive 7 months ago
I practiced a similar question where we had to modify a vector and then print it, but I can't recall if the set will reflect those changes too.
FR
Freeman 7 months ago
I remember something about how sets work with custom classes, but I'm not sure if they will actually store the modified values after using `add10`.
TA
Tamala 7 months ago
I think there might be a compilation error because of the `this?>a` line in the `setA` method. That doesn't look right.
0/2000 characters

Save Cancel