New Year Sale 2026! 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 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:

0/2000 characters
Teri
3 months ago
No way, I thought it would output 2 3 4 5 6 7!
upvoted 0 times
...
Caprice
3 months ago
I thought it would include more numbers, weird!
upvoted 0 times
...
Celeste
4 months ago
Wait, how does it skip 2-7? Seems off.
upvoted 0 times
...
Louvenia
4 months ago
Totally agree, that's the right output!
upvoted 0 times
...
Bernardine
4 months ago
The program outputs: 0 1 8 9.
upvoted 0 times
...
Curtis
4 months ago
I’m confused about the order of elements in the output. I think it might be sorted, but I can't recall exactly how that affects the final result.
upvoted 0 times
...
Jaime
4 months ago
This reminds me of a practice question where we had to manipulate sets. I feel like the output should be the remaining elements after the erase operation.
upvoted 0 times
...
Hubert
5 months ago
I'm not entirely sure, but I remember something about lower_bound and upper_bound removing elements in a range.
upvoted 0 times
...
Blair
5 months ago
I think the set will only keep unique values, so duplicates from the vector won't affect the output.
upvoted 0 times
...
Julie
5 months ago
This is a good test of understanding set data structures and their methods. I'll make sure to carefully trace the logic to arrive at the correct answer.
upvoted 0 times
...
Elbert
5 months ago
I'm feeling pretty confident about this one. The set operations are straightforward, and I can see the final output taking shape as the code progresses.
upvoted 0 times
...
Antonio
5 months ago
Okay, I think I've got this. The key is understanding how the set is being modified by the insert and erase operations. I'll work through it systematically.
upvoted 0 times
...
Magda
5 months ago
This looks like a tricky one. I'll need to carefully step through the code and think through the set operations to figure out the output.
upvoted 0 times
...
Teresita
5 months ago
Hmm, I'm a bit confused by the set operations here. Let me re-read the question and try to visualize what's happening step-by-step.
upvoted 0 times
...
Rozella
5 months ago
I'm a bit confused by the options here. I'll need to carefully review the descriptions and think about the specific responsibilities of each listener to determine the right answer.
upvoted 0 times
...
Zita
5 months ago
Okay, I think I've got a strategy here. I'll focus on the table aliases and join syntax options, since those seem like the most straightforward performance factors to evaluate.
upvoted 0 times
...
Martina
9 months ago
Hey, at least they're not using a linked list. That would be even more boring!
upvoted 0 times
Katina
8 months ago
User 3
upvoted 0 times
...
Jordan
9 months ago
User 2
upvoted 0 times
...
Mabel
9 months ago
User 1
upvoted 0 times
...
...
Joaquin
9 months ago
Wait, so this code is just a bunch of people playing with containers? I thought programming was supposed to be more exciting than that!
upvoted 0 times
...
Fabiola
10 months ago
D has got to be the right answer. The program is just playing with the vector and set, so the output should be the original integers in some order.
upvoted 0 times
...
Royal
10 months ago
Hmm, I think the answer is A. The program seems to be doing some weird set operations, but I'm not sure why the output would be 0 1 8 9.
upvoted 0 times
...
Lyndia
10 months ago
I'm pretty sure the answer is C. The set will only contain unique elements, and the erase operation will remove the range [2, 7], leaving 1, 6, 5, and 7.
upvoted 0 times
Johnson
8 months ago
Let's see the correct answer: B) program outputs: 2 3 4 5 6 7
upvoted 0 times
...
Theresia
8 months ago
Actually, I'm pretty sure it's B.
upvoted 0 times
...
Vince
8 months ago
No, I believe it's A.
upvoted 0 times
...
Emmett
8 months ago
I think the answer is C.
upvoted 0 times
...
...
Nickole
11 months 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
Naomi
10 months ago
That makes sense, the set is sorted and the elements in the range [2, 7] are erased.
upvoted 0 times
...
Naomi
10 months ago
B) program outputs: 2 3 4 5 6 7
upvoted 0 times
...
...
Haley
11 months ago
But the set will only contain unique elements, so I still think it's B.
upvoted 0 times
...
Lonny
11 months ago
I disagree, I believe the answer is C.
upvoted 0 times
...
Haley
11 months ago
I think the answer is B.
upvoted 0 times
...

Save Cancel