#include "Complex.h"
#include<iostream>
#include<cmath>
using namespace std;
Complex::Complex():real(0),image(0)
{
}
Complex::Complex(double r):real(r),image(0)
{
}
Complex::Complex(double r,double i):real(r),image(i)
{
}
void Complex::setValue(double r,double i)
{
this->real=r;
this->image=i;
}
double Complex::getReal()const
{
return real;
}
double Complex::getImage()const
{
return image;
}
double Complex::getDistance()const
{
cout<<this->real<<" "<<this->image<<" ";
return sqrt((pow(this->real,2)+pow(this->image,2)));
}
void Complex::output()const
{
if(image >0)
cout<<real<<"+"<<image<<"i"<<endl;
else if(image<0)
cout<<real<<image<<"i"<<endl;
else
cout<<real<<endl;
}
Complex Complex::add(const Complex & c)const
{
return c.image+image;
}
Complex Complex::multiply(const Complex & c)const
{
int r=c.real*real-c.image*image;
int i=c.real*image-c.image*real;
Complex p;
p.real=r;p.image=i;
return p;
}