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

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 getA()
B) it will not compile
A) it will compile and print 7
C) it will compile but the program result is unpredictable
D) adding code: bool operator !=(const A & b) const { if (this?>a != b.a) { return true; } return false; } at Place 1 will allow the program to compile

C++ Institute CPP Exam - Topic 3 Question 129 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 129
Topic #: 3
[All CPP Questions]

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;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters

Currently there are no comments in this discussion, be the first to comment!


Save Cancel