Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class Complex
5.
{
6.
private:
7.
double real;
8.
double imag;
9.
public:
10.
Complex(double r = 0.0, double i = 0.0) : real(r), imag(i)
11.
{}
12.
double mag()
13.
{
14.
return getMag();
15.
}
16.
operator double ()
17.
{
18.
return getMag();
19.
}
20.
private:
21.
double getMag()
22.
{
23.
return sqrt(real * real + imag * imag);
24.
}
25.
};
26.
int main()
27.
{
28.
Complex com(3.0, 4.0);
29.
cout
Options:
A .  5 5
B .  4 5
C .  6 6
D .  None of the mentioned
Answer: Option A

In this program, we are calculating the magnitude value by two ways.
Output:
$ g++ con3.cpp
$ a.out
55



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers