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 9 Question 87 Discussion

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

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

#include

#include

#include

using namespace std;

int main(){

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

vectorv(myints, myints+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<<*i<<" ";

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Nickole
3 days ago
The correct answer is B. The program first creates a vector with the given integers, then creates a set from the vector, inserts the vector elements into the set, and finally erases the elements in the range [2, 7]. The resulting set contains the elements 2, 3, 4, 5, 6, 7, which are then printed.
upvoted 0 times
...
Haley
6 days ago
But the set will only contain unique elements, so I still think it's B.
upvoted 0 times
...
Lonny
9 days ago
I disagree, I believe the answer is C.
upvoted 0 times
...
Haley
11 days ago
I think the answer is B.
upvoted 0 times
...

Save Cancel