Untitled
unknown
c_cpp
a year ago
1.5 kB
9
Indexable
#include<iostream> #include<math.h> using namespace std; class Cmycomplex { friend Cmycomplex operator*(double a,Cmycomplex &z); friend int main(); private: double x,y; public: Cmycomplex(double xx=0,double yy=0) { x=xx; y=yy; } void Set(double xx,double yy) { x=xx; y=yy; } Cmycomplex operator+(Cmycomplex &z) { Cmycomplex t; t.x=x+z.x; t.y=y+z.y; return t; } Cmycomplex operator-(Cmycomplex &z) { Cmycomplex t; t.x=x-z.x; t.y=y-z.y; return t; } Cmycomplex operator*(Cmycomplex &z) { Cmycomplex t; t.x=x*z.x-y*z.y; t.y=x*z.y+y*z.x; return t; } Cmycomplex operator/(Cmycomplex &z) { Cmycomplex t; t.x=(x*z.x+y*z.y)/(z.x*z.x+z.y*z.y); t.y=((-1)*x*z.y+y*z.x)/(z.x*z.x+z.y*z.y); return t; } Cmycomplex sqrt() { Cmycomplex t; t.x=pow((x+pow(x*x+y*y,0.5))/2,0.5); t.y=y/pow(2*x+2*pow(x*x+y*y,0.5),0.5); return t; } void Show() { if(y>0) printf("(%.2lf+%.2lfi)",x,y); if(y=0) printf("(%.2lf+%.2lfi)",x,y); if(y<0) printf("(%.2lf-%.2lfi)",x,-y); } }; Cmycomplex operator*(double a,Cmycomplex &z) { Cmycomplex t; t.x=a*z.x; t.y=a*z.y; return t; } int main () { double a,b,c,d,e,f; cin>>a>>b; cin>>c>>d; cin>>e>>f; Cmycomplex z1(a,b),z2(c,d),z3(e,f),z4,z5,z6,z7,z8,w1,w2,w3,w4,w5; z6=z2*z2; z7=4*z1; z8=z7*z3; z4=z6-z8; w1=(-1)*z2; w2=z4.sqrt(); w3=w1+w2; w4=0.5*w3; w5=w4/z1; w5.Show(); return 0; }
Editor is loading...
Leave a Comment