All pastes #1964126 Raw Edit

Something

public cpp v1 · immutable
#1964126 ·published 2010-10-16 16:57 UTC
rendered paste body
#include <iostream>#include <math.h>#include <complex>#include <iomanip>#define pi 3.141592using 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<double> 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<double> yStandart (complex<double>z){	return(complex<double>(0,1)+z*sinh(complex<double>(1,0)+z));}void table (void){	Complex z1 (1,0);	complex<double>z2(z1.Re(),z1.Im());	for (int i=0; i<9; i++)	{		z1=Complex(1,i*pi/4.);		z2=complex<double>(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<<endl<<"     \t";	cin>>a>>b;	Complex z (a, b);	complex<double>z2(z.Re(),z.Im());	cout<<"\n   \t"<<yMyClass(z);	cout<<"\n   \t"<<yStandart(z2);	cout<<"\n "<<((yMyClass(z)==yStandart(z2))?"":"");}main (void){	setlocale (LC_ALL, "rus");	Complex a(2,2);	Complex b(2,3);	cout << sh(a+b*a)		<< endl <<		sinh(complex <double>(a.Re(),a.Im())+complex<double>(b.Re(),b.Im())*complex<double>(a.Re(),a.Im()));	table ();	comparison ();	/*float a, b;	cout<<endl<<"     \t";	cin>>a>>b;	Complex z (a, b);	complex<double>z2(z.re(),z.im());*/	cin.get();	cin.get();	return 0;}