# Untitled

unknown
plain_text
17 days ago
2.3 kB
1
Indexable
Never
```#include<iostream>
#include<math.h>
using namespace std;
class Cmycomplex
{
friend Cmycomplex operator*(double a,Cmycomplex &z);
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;
}
bool a()
{
if(y>0)
{
return 1;
}
else
return 0;
}
bool b()
{
if(x==0&&y==0)
{
return 1;
}
else
return 0;
}
bool c()
{
if(x<0&&y==0)
{
return 1;
}
else
return 0;
}
int d()
{
return (-1)*x;
}
void Show()
{
if(y>=0)
printf("(%.2lf+%.2lfi)\n",x,y);
else
printf("(%.2lf-%.2lfi)\n",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,u;
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,w6,w7,w8,p1,p2,p3,q1,q2,q3,q4,q5,q6,q7,q8;
z6=z2*z2;
z7=4*z1;
z8=z7*z3;
z4=z6-z8;
if(z4.b()==0&&z4.c()==0)
{
w1=(-1)*z2;
w2=z4.sqrt();
w3=w1+w2;
w4=0.5*w3;
w5=w4/z1;
w6=w1-w2;
w7=0.5*w6;
w8=w7/z1;
if(w5.a()>0)
{
w5.Show();
w8.Show();
}
else
{
w8.Show();
w5.Show();
}
}
else if(z4.b()>0&&z4.c()==0)
{
p1=(-1)*z2;
p2=0.5*p1;
p3=p2/z1;
p3.Show();
p3.Show();
}
else if(z4.b()==0&&z4.c()>0)
{
u=z4.d();
u=sqrt(u);
q1=(-1)*z2;
q2.Set(0,u);
q3=q1+q2;
q4=0.5*q3;
q5=q4/z1;
q6=q1-q2;
q7=0.5*q6;
q8=q7/z1;
if(q5.a()>0)
{
q5.Show();
q8.Show();
}
else
{
q8.Show();
q5.Show();
}

}
return 0;
}```