-
What is the output of this program?
#include <iostream>
#include <cmath>
using namespace std;
class ComplexNumber
{
private:
double RealNumber;
double ImagNumber;
public:
ComplexNumber(double r = 0.0, double i = 0.0) : RealNumber(r), ImagNumber(i)
{}
double mag()
{
return getMag();
}
operator double ()
{
return getMag();
}
private:
double getMag()
{
return sqrt(RealNumber * RealNumber + ImagNumber * ImagNumber);
}
};
int main()
{
ComplexNumber comp(2.0, 5.0);
cout << comp.mag()<<" ";
cout << comp;
return 0;
}
-
- 2.0
- 5.0
- 5.38516
- 5.38516 5.38516
- None of these
Correct Option: D
In this program, we are calculating the magnitude value by two ways.