#include #include #include #include #define pi 3.141592 using namespace std; class Complex { double mod, arg; public: Complex () {mod=1; arg=0;} Complex (double m, double a) {arg=a; mod=(m>=0) ? m : -m;} Complex (double m) {arg=0; mod=(m>=0) ? m : -m;} double Im() {return mod*sin(arg); } double Re() {return mod*cos(arg); } friend ostream& operator <<(ostream& f, Complex a) {f << "(" << a.Re() << "," << a.Im() << ")"; return f;} friend istream& operator >>(istream& f, Complex& a) {f >> a.mod >> a.arg; return f;} friend Complex operator + (Complex, Complex); friend Complex operator * (Complex, Complex);// {return Complex(re*a.re-im*a.im, re*a.im+im*a.re);} bool operator ==(complex a) {return Re()==a.real() && Im()==a.imag();} friend Complex sh (Complex b);/*{ Complex a; a.re=sinh(b.re)*cos(b.im); a.im=cosh(b.re)*sin(b.im); return a; }*/ }; Complex sh (Complex b) { double re, im; re=sinh(b.Re())*cos(b.Im()); im=cosh(b.Re())*sin(b.Im()); b.mod=sqrt(pow(re,2)+pow(im,2)); /*if (im>=0)*/ b.arg=acos(re/b.mod); /*else b.arg=2*pi-acos(re/b.mod);*/ return b; } Complex operator + (Complex a, Complex b) { Complex c; double x = a.Re() + b.Re(); double y = a.Im() + b.Im(); c.mod = sqrt(pow(x,2)+pow(y,2)); c.arg = atan(y/x); //if(x<0) c.arg += pi; return c; } Complex operator *(Complex a, Complex b) { Complex c; c.arg = a.arg + b.arg; /*if(c.arg>pi) c.arg -= 2*pi; if(c.arg<-pi) c.arg+= 2*pi;*/ c.mod = a.mod*b.mod; return c; /*double re,im; re=a.Re()*b.Re()-a.Im()*b.Im(); im=a.Re()*b.Im()+a.Im()*b.Re(); return Complex(sqrt(pow(re,2)+pow(im,2)),atan(im/re));*/ } Complex yMyClass (Complex z) { return (Complex(1,pi/2.0)+z*sh(Complex(1)+z)); } complex yStandart (complexz) { return(complex(0,1)+z*sinh(complex(1,0)+z)); } void table (void) { Complex z1 (1,0); complexz2(z1.Re(),z1.Im()); for (int i=0; i<9; i++) { z1=Complex(1,i*pi/4.); z2=complex(z1.Re(), z1.Im()); cout << "\n" << setw(5) << z1 << " " << setw(20) << yMyClass(z1) << "\t" << setw(5) << z2 << " " << setw(20) << yStandart(z2); } } void comparison (void) { float a, b; cout<>a>>b; Complex z (a, b); complexz2(z.Re(),z.Im()); cout<<"\n \t"<(a.Re(),a.Im())+complex(b.Re(),b.Im())*complex(a.Re(),a.Im())); table (); comparison (); /*float a, b; cout<>a>>b; Complex z (a, b); complexz2(z.re(),z.im());*/ cin.get(); cin.get(); return 0; }