-
What is the output of this program?
#include <iostream>
using namespace std;
class ComplexNumber
{
private:
float R;
float I;
public:
ComplexNumber():R(0), I(0){}
ComplexNumber operator ()(float real, float imag)
{
R += real;
I += imag;
return *this;
}
ComplexNumber operator() (float real)
{
R += real;
return *this;
}
void Print()
{
cout << "(" << R << "," << I << ")" << endl;
}
};
int main()
{
ComplexNumber comp1, comp2;
comp2 = comp1(5.1, 2.5);
comp1(3.4, 3.5);
comp2(4.3);
cout << "Complecx Number = ";comp1.Print();
cout << "Complecx Number = ";comp2.Print();
return 0;
}
-
- Complecx Number = (0,6)
Complecx Number = (2,3.2) - Complecx Number = (5.1,2.5)
Complecx Number = (2,3.2) - Complecx Number = (8.5,6)
Complecx Number = (9.4,2.5) - Compilation Error
- None of these
- Complecx Number = (0,6)
Correct Option: C
In this program, We are returning the real and imaginary part of the complex number by using function call operator.