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 113 Discussion

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

Which changes introduced independently will allow code to compile and display 0 1 8 9 (choose all that apply)

#include

#include

#include

using namespace std;

class A {

int a;

public:

A(int a):a(a){}

int getA() const { return a;}

/* Insert Code Here 1 */

};

/* Insert Code Here 2 */

int main(){

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

vectorv(t, t+10);

set s1(v.begin(),v.end());

s1.insert(v.begin(),v.end());

s1.erase(s1.lower_bound(2),s1.upper_bound(7));

for(set::iterator i=s1.begin();i!= s1.end(); i++) {

cout<getA()<<" ";

}

cout<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: A, B, D

Contribute your Thoughts:

Tequila
13 hours ago
This question is testing our understanding of operator overloading and how it affects the behavior of the `set` container. I think I need to carefully consider the different options and how they would impact the sorting and insertion of the `A` objects into the `set`.
upvoted 0 times
...
Jarvis
9 days ago
I think option B is the correct answer. Defining the less-than operator to compare the 'a' member of the A class will allow the set to properly order the elements.
upvoted 0 times
...

Save Cancel