What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Complex
{
private:
float real;
float imag;
public:
Complex():real(0), imag(0){}
Complex operator ()(float re, float im)
{
real += re;
imag += im;
return *this;
}
Complex operator() (float re)
{
real += re;
return *this;
}
void display()
{
cout << "(" << real << "," << imag << ")" << endl;
}
};
int main()
{
Complex c1, c2;
c2 = c1(3.2, 5.3);
c1(6.5, 2.7);
c2(1.9);
cout << "c2=";c1.display();
cout << "c2=";c2.display();
return 0;
}
#include <iostream>
using namespace std;
class Complex
{
private:
float real;
float imag;
public:
Complex():real(0), imag(0){}
Complex operator ()(float re, float im)
{
real += re;
imag += im;
return *this;
}
Complex operator() (float re)
{
real += re;
return *this;
}
void display()
{
cout << "(" << real << "," << imag << ")" << endl;
}
};
int main()
{
Complex c1, c2;
c2 = c1(3.2, 5.3);
c1(6.5, 2.7);
c2(1.9);
cout << "c2=";c1.display();
cout << "c2=";c2.display();
return 0;
}
A. c2=(9.7,8)
c2=(5.1,5.3)
B. c2=(9,8)
c2=(5,5)
C. c2=(4.7,8)
c2=(2.1,5.3)
D. c2=(5.7,8)
c2=(5.1,5.6)
Answer: Option A
Join The Discussion