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 5 Question 106 Discussion

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

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

#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; }

};

int main () {

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

deque d (t,t+15);

int number = count(d.begin(), d.end(), 2);

cout<< number<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Asha
1 months ago
This is too easy, the answer has to be B. I mean, come on, counting occurrences of a number? That's like programming 101. Unless... there's some kind of sneaky twist I'm missing. Nah, I'm sticking with B.
upvoted 0 times
Ilene
9 days ago
I'm with you guys, B seems like the correct answer here.
upvoted 0 times
...
Cecilia
13 days ago
Yeah, counting occurrences is a basic concept. B sounds right to me too.
upvoted 0 times
...
Arlette
15 days ago
I agree, it seems pretty straightforward. B is the most likely answer.
upvoted 0 times
...
...
Stevie
1 months ago
Haha, the code looks like it was written by a prankster. Throwing in a random class A just to confuse us. But I'm not falling for that trap, I'm going with B!
upvoted 0 times
...
Adelle
1 months ago
Wait, wait, wait... why is there a class A in the code? Is that just a red herring or is it somehow relevant? Ah, who cares, I'll just go with the most straightforward answer, which is B.
upvoted 0 times
Salley
22 hours ago
I think the class A is just there to confuse us, the answer is B.
upvoted 0 times
...
...
Wava
2 months ago
Oh, that makes sense. I see your point now.
upvoted 0 times
...
Ira
2 months ago
I disagree, I believe the answer is A) 4 because there are 4 occurrences of the number 2 in the deque
upvoted 0 times
...
Cornell
2 months ago
Hmm, this looks like a simple problem of counting occurrences of a number in a container. I'll go with option B, since 2 appears 3 times in the given array.
upvoted 0 times
Fatima
5 days ago
So, the output will be 3.
upvoted 0 times
...
Brande
20 days ago
Yes, because there are 3 occurrences of 2 in the array.
upvoted 0 times
...
Delbert
21 days ago
I agree, it should be 3.
upvoted 0 times
...
Rueben
1 months ago
I think the answer is B.
upvoted 0 times
...
...
Wava
2 months ago
I think the answer is B) 3
upvoted 0 times
...

Save Cancel