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 CPA-21-02 Exam - Topic 1 Question 13 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 13
Topic #: 1
[All CPA-21-02 Questions]

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

#include

using namespace std;

class complex{

double re;

double im;

public:

complex() : re(0),im(0) {}

complex(double x) { re=x,im=x;};

complex(double x,double y) { re=x,im=y;}

void print() { cout << re << " " << im;}

};

int main(){

complex c1(1,2);

c1.print();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Larue
3 months ago
The constructor is set up right, so no errors here!
upvoted 0 times
...
Cassandra
4 months ago
I thought it would throw a compilation error.
upvoted 0 times
...
Dorathy
4 months ago
Wait, how does it not print 1 1?
upvoted 0 times
...
Izetta
4 months ago
Totally agree, option C is correct!
upvoted 0 times
...
Sharmaine
4 months ago
It prints: 1 2
upvoted 0 times
...
Marg
5 months ago
I hope there's no compilation error, but I guess it could happen if the constructors were not set up right.
upvoted 0 times
...
Cherrie
5 months ago
I practiced a similar question, and I feel like it might print 1 1 instead, but I can't recall why.
upvoted 0 times
...
Wynell
5 months ago
I'm not entirely sure, but I remember something about constructor overloading. Does it mean it will print 1 2?
upvoted 0 times
...
Bettina
5 months ago
I think the code should compile fine since all the constructors are defined correctly.
upvoted 0 times
...
Leandro
5 months ago
Hmm, this is a good test of understanding object-oriented programming and constructor overloading. I'll need to carefully read through the code and think about how the complex class is designed before I can determine the output.
upvoted 0 times
...
Daren
5 months ago
I'm a bit confused here. The complex class has three constructors, and I'm not sure which one is being called when we create c1. I'll need to double-check the syntax and behavior of the different constructors to figure this out.
upvoted 0 times
...
Odette
5 months ago
I'm pretty confident this is going to print 1 2. The complex constructor that takes two arguments is being used, and the print() function should just output the real and imaginary parts as specified.
upvoted 0 times
...
Josphine
5 months ago
Okay, let me think this through step-by-step. We're creating a complex number object c1 with real part 1 and imaginary part 2, and then calling the print() function. I'm guessing the answer has to do with how the print() function is implemented.
upvoted 0 times
...
Marleen
5 months ago
Hmm, this looks like a tricky one. I'll need to carefully trace the code to figure out what's happening with the complex class and its constructors.
upvoted 0 times
...
Chaya
5 months ago
I think the answer is C - scalability. VoIP systems require a lot of bandwidth, so the network needs to be able to scale up to support the increased traffic.
upvoted 0 times
...
Milly
5 months ago
Hmm, I'm not sure about A. I'll have to double-check the details on Blue Prism's web service security features.
upvoted 0 times
...
Minna
5 months ago
I'm a little unsure about this one. The question is asking for a specific term, and I'm not totally familiar with all the different analysis techniques we've covered. I'll have to make an educated guess, but I'm not 100% confident in my answer.
upvoted 0 times
...
Chana
5 months ago
I remember we discussed that selling prices and competitive forces matter, but I'm confused about whether reporting currency plays a role.
upvoted 0 times
...
Janey
6 months ago
I'm a bit confused, but copying and pasting into the layout panel seems tempting. I might second-guess that though.
upvoted 0 times
...
Cornell
10 months ago
Wait, so the answer is not 42? Darn, I thought C++ was all about the answer to the ultimate question of life, the universe, and everything.
upvoted 0 times
...
Whitney
10 months ago
Hmm, this code looks like it was written by a complex person. Get it? Complex? Ah, never mind.
upvoted 0 times
...
Jeannetta
10 months ago
I'm surprised that the compiler doesn't catch the issue with the constructors. Maybe it's a feature, not a bug!
upvoted 0 times
Jodi
9 months ago
D) Compilation error
upvoted 0 times
...
Paris
9 months ago
B) It prints: 1 1
upvoted 0 times
...
Mitzie
9 months ago
A) It prints: 1 2
upvoted 0 times
...
...
Nu
10 months ago
The output should be 1 2, as the `complex` object `c1` is initialized with 1 and 2 in the `main()` function.
upvoted 0 times
...
Francoise
10 months ago
The correct answer is D. Compilation error. The class `complex` has two private member variables `re` and `im`, and the constructors are not initializing them properly.
upvoted 0 times
Annabelle
8 months ago
So, the correct answer is D. Compilation error.
upvoted 0 times
...
Rikki
8 months ago
The constructors are not initializing the private member variables correctly.
upvoted 0 times
...
Breana
9 months ago
Why does it give a compilation error?
upvoted 0 times
...
...
Hyman
11 months ago
But the constructor for c1 is (1,2), so it should print 1 2, right?
upvoted 0 times
...
Juliana
11 months ago
I disagree, I believe the answer is A) It prints: 0 0
upvoted 0 times
...
Hyman
11 months ago
I think the answer is B) It prints: 1 1
upvoted 0 times
...

Save Cancel