Question: Please help me fix the error for the following code: #include #include #include #include complex.h Complex::Complex() { real = 0.0; imag = 0.0; } Complex::Complex(double

Please help me fix the error for the following code:

#include

#include

#include

#include "complex.h"

Complex::Complex()

{

real = 0.0;

imag = 0.0;

}

Complex::Complex(double r)

{

real = r;

imag = 0.0;

}

Complex::Complex(double r, double i)

{

real = r;

imag = i;

}

double Complex::getReal()const

{

return real;

}

double Complex::getImag() const

{

return imag; //these are accessor member functions

}

Complex Complex::conjugate()const

{

return Complex(real,-imag);

}

Complex::Complex modulus() const

{

return Complex(sqrt((pow(real,2))+(pow(imag,2))));

}

Complex::Complex arguement() const

{

if (real == 0 && imag == 0)

{

throw -2;

}

return atan2(imag,real); //these are other member functions

}

Complex operator+(const Complex& z1, const Complex& z2)

{

return Complex(z1.real+z2.real,z1.imag+z2.imag);

}

Complex operator-(const Complex& z1, const Complex& z2)

{

return Complex(z1.real-z2.real, z1.imag-z2.imag);

}

Complex operator*(const Complex& z1, const Complex& z2)

{

double real = z1.real * z2.real - z1.imag * z2.imag;

double imag = z1.real * z2.imag + z1.imag * z2.real;

return Complex(real, imag);

}

Complex operator/(const Complex& z1, const Complex& z2)

{

double divisor = z2.real * z2.real + z2.imag * z2.imag;

if (divisor == 0.0)

{

throw -1;

}

double real = (z1.real * z2.real + z1.imag * z2.imag) / divisor;

double imag = (z1.imag * z2.real - z1.real * z2.imag) / divisor;

}

Complex pow(const Complex& z, int n)

{

if (n == 0)

{

return Complex (1.0);

}

else if (n == 1)

{

return z;

}

else if (n

{

return 1 / pow(z, -n);

}

else

{

for (int i = 0; i

return Complex(z * pow(z, n-1));

}

}

ostream& operator

{

if (z.real == 0 && z.imag == 0)

{

out

return out;

}

if (z.real == 0)

{

if (z.imag

{

if (z.imag != -1)

out

else

out

}

else

{

if (z.imag != 1)

out

else

out

}

return out;

}

if (z.imag == 0)

{

out

return out;

}

out

if (z.imag

{

if (z.imag != -1)

out

else

out

}

else

{

if (z.imag != 1)

out

else

out

}

return out;

}

Please help me fix the error for the following code: #include #include

#include #include "complex.h" Complex::Complex() { real = 0.0; imag = 0.0; }

input ompilation failed due to following error(s). | complex. cpp:147:22: error: 'double Complex: :imag' is private within this context 147 input Compilation failed due to following error(s). complex. spp:45:1: error: 'Complex::Complex' names the constructor, not the type 45 I Complex: :Complex modulus() const complex, crr:49:1: error: 'Complex::Complex' names the constructor, not the type 49 I Complex: :Complex arguement() const

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!