/* 09-11-20 FRI Obj_*/
#include<iostream>
using namespace std;
class Complex
{
private :
double real;
double image;
public:
Complex(double r=0,double i=0);
void ShowComplex();
void ShowComplex(char);
void SetReal(double r);
void SetImage(double i);
double GetReal();
double GetImage();
void ReFresh(double r, double i);
Complex operator+(Complex B);
Complex operator-(Complex B);
Complex operator*(Complex B);
Complex operator/(Complex B);
void OPer(char op, Complex a, Complex b);
};
Complex::Complex(double r, double i){
real = r; image = i; }
void Complex::OPer(char op, Complex a, Complex b){
if(op=='+'){
real = a.GetReal() + b.GetReal();
image = a.GetImage() + b.GetImage();
}else if(op=='-'){
real = a.GetReal() - b.GetReal();
image = a.GetImage() - b.GetImage();
}
}
void Complex::ReFresh(double r, double i){
real = r; image = i; }
void Complex::SetReal(double r) { real = r; }
void Complex::SetImage(double i) { image = i; }
double Complex::GetReal() { return real; }
double Complex::GetImage() { return image; }
void Complex::ShowComplex(){
cout<<"("<< real <<" + "<< image <<" i )"<<endl; }
void Complex::ShowComplex(char ch){
cout<<"("<< real <<" "<<ch<<" "<< image <<" i )"<<endl; }
Complex Complex::operator+(Complex B)
{
Complex Temp;
Temp.SetReal(B.GetReal() + this->GetReal());
Temp.SetImage(B.GetImage() + this->GetImage());
return Temp;
}
Complex Complex::operator-(Complex B)
{
Complex Temp;
Temp.SetReal( this->GetReal() - B.GetReal() );
Temp.SetImage(this->GetImage() - B.GetImage());
return Temp;
}
Complex Complex::operator*(Complex B)
{
Complex Temp;
Temp.SetReal((B.GetReal() * this->GetReal()) - (B.GetImage()*this->GetImage() ) );
Temp.SetImage((B.GetReal() * this->GetImage()) + (this->GetReal() * B.GetImage()) );
return Temp;
}
Complex Complex::operator/(Complex B)
{
double a,b,c,d;
Complex Temp;
a=this->GetReal();
b=this->GetImage();
c=B.GetReal();
d=B.GetImage();
Temp.SetReal( ((a*c)-(b*d))/((c*c)+(d*d)) );
Temp.SetImage( (a*d-c*b) / ( c*c+d+d) );
return Temp;
}
void main()
{
Complex x(10,20);
Complex y(20,5);
Complex z;
cout<<"x = "; x.ShowComplex();
cout<<"y = "; y.ShowComplex();
cout<<"z = "; z.ShowComplex();
cout<<endl;
/*z.ReFresh( x.GetReal() + y.GetReal(),
x.GetImage() + y.GetImage()
);
*/
cout<<"OPER : *"<<endl;
z=x*y;
x.ShowComplex();
y.ShowComplex();
z.ShowComplex();
cout<<endl;
cout<<"OPER : /"<<endl;
z=x/y;
x.ShowComplex();
y.ShowComplex();
}