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

Posted by Kimberely on Apr 24, 2024 at 05:17 PM

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;

}

Suggested Answer: B

Get Premium CPA-21-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
33 comments · newest first
LA
Larue 11 months ago
The constructor is set up right, so no errors here!
CA
Cassandra 11 months ago
I thought it would throw a compilation error.
DO
Dorathy 11 months ago
Wait, how does it not print 1 1?
IZ
Izetta 11 months ago
Totally agree, option C is correct!
SH
Sharmaine 11 months ago
It prints: 1 2
MA
Marg 12 months ago
I hope there's no compilation error, but I guess it could happen if the constructors were not set up right.
CH
Cherrie 12 months ago
I practiced a similar question, and I feel like it might print 1 1 instead, but I can't recall why.
WY
Wynell 12 months ago
I'm not entirely sure, but I remember something about constructor overloading. Does it mean it will print 1 2?
BE
Bettina 1 year ago
I think the code should compile fine since all the constructors are defined correctly.
LE
Leandro 1 year 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.
DA
Daren 1 year 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.
OD
Odette 1 year 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.
JO
Josphine 1 year 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.
MA
Marleen 1 year 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.
CH
Chaya 1 year 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.
MI
Milly 1 year ago
Hmm, I'm not sure about A. I'll have to double-check the details on Blue Prism's web service security features.
MI
Minna 1 year 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.
CH
Chana 1 year ago
I remember we discussed that selling prices and competitive forces matter, but I'm confused about whether reporting currency plays a role.
JA
Janey 1 year ago
I'm a bit confused, but copying and pasting into the layout panel seems tempting. I might second-guess that though.
CO
Cornell 1 year 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.
WH
Whitney 1 year ago
Hmm, this code looks like it was written by a complex person. Get it? Complex? Ah, never mind.
JE
Jeannetta 1 year ago
I'm surprised that the compiler doesn't catch the issue with the constructors. Maybe it's a feature, not a bug!
JO
Jodi 1 year ago
↳ replying to Jeannetta
D) Compilation error
PA
Paris 1 year ago
↳ replying to Jeannetta
B) It prints: 1 1
MI
Mitzie 1 year ago
↳ replying to Jeannetta
A) It prints: 1 2
NU
Nu 1 year ago
The output should be 1 2, as the `complex` object `c1` is initialized with 1 and 2 in the `main()` function.
FR
Francoise 1 year 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.
AN
Annabelle 1 year ago
↳ replying to Francoise
So, the correct answer is D. Compilation error.
RI
Rikki 1 year ago
↳ replying to Francoise
The constructors are not initializing the private member variables correctly.
BR
Breana 1 year ago
↳ replying to Francoise
Why does it give a compilation error?
HY
Hyman 2 years ago
But the constructor for c1 is (1,2), so it should print 1 2, right?
JU
Juliana 2 years ago
I disagree, I believe the answer is A) It prints: 0 0
HY
Hyman 2 years ago
I think the answer is B) It prints: 1 1
0/2000 characters

Save Cancel