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 1 Question 85 Discussion

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

Which changes introduced independently will allow the code to compile and display ''one'' ''eight'' ''nine'' ''ten''? 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(){

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

string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"};

multimap m;/* Replace Code Here 3 */

for(int i=0; i<10; i++) {

m.insert(pair(A(t[i]),s[i]));

}

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

multimap::iterator i=m.begin();/* Replace Code Here 4 */

for( ; i!= m.end(); i++) {

cout<second<<" ";

}

cout<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Lashonda
1 months ago
I'm going to go with options B and D. The custom comparator seems like a cleaner solution than overloading the less-than operator directly on the A class.
upvoted 0 times
Tennie
26 days ago
User 2
upvoted 0 times
...
Melynda
27 days ago
User 1
upvoted 0 times
...
...
Kris
1 months ago
Option D looks promising, but I'm not sure about the custom comparator. Shouldn't we just use the default less-than operator for the A class?
upvoted 0 times
...
Wenona
1 months ago
Haha, the problem says 'choose all that apply', so I'm going to mark all of them just to be safe! Better too many than too few, right?
upvoted 0 times
...
Lenna
1 months ago
I think option B is the correct answer. Comparing the object's 'a' member directly should allow the multimap to sort the keys properly.
upvoted 0 times
...
Valene
2 months ago
Hmm, you might be right. Let's see which option actually works when we try to compile the code.
upvoted 0 times
...
Pauline
2 months ago
I disagree, I believe option D is the correct choice because it provides the necessary comparison function for the multimap.
upvoted 0 times
...
Valene
2 months ago
I think option A will allow the code to compile and display the desired output.
upvoted 0 times
...

Save Cancel