Đến đây là tịt có ai giúp e với ạ
class complex
{
private int realPart;
private int imaginaryPart;
public complex()
{
realPart = 0 ;
imaginaryPart = 0;
}
public complex(int valreal, int valimaginary)
{
realPart = valreal;
imaginaryPart = valimaginary;
}
public void Readcomplex()
{
Console.WriteLine("Enter realPart: ");
realPart = int.Parse(Console.ReadLine());
Console.Write("Enter imaginaryPart: ");
imaginaryPart = int.Parse(Console.ReadLine());
}
public void PrintComplex()
{
Console.WriteLine(realPart + "+" + imaginaryPart + "i");
}
public void SetReal(int realVal)
{
realPart = realVal;
}
public void Setimaginary(int imaginaryVal)
{
imaginaryPart = imaginaryVal;
}
public void SetComplex(int realVal, int imaginaryVal)
{
realPart = realVal;
imaginaryPart = imaginaryVal;
}
public int GetReal()
{
return realPart;
}
public int GetImaginary()
{
return imaginaryPart;
}
public complex GetComplex()
{
complex a = new complex();
return a;
}
public void AddComplex(complex a, complex b)
{
realPart = a.realPart + b.realPart;
imaginaryPart = a.imaginaryPart + b.imaginaryPart;
}
public static complex operator +(complex a, complex b)
{
complex c = new complex();
c.realPart = a.realPart + b.realPart;
c.imaginaryPart = a.imaginaryPart + b.imaginaryPart;
return c;
}
public void subComplex(complex a, complex b)
{
realPart = a.realPart - b.realPart;
imaginaryPart = a.imaginaryPart - b.imaginaryPart;
}
public static complex operator -(complex a, complex b)
{
complex c = new complex();
c.realPart = a.realPart - b.realPart;
c.imaginaryPart = a.imaginaryPart - b.imaginaryPart;
return c;
}
public void MultiplyComplex(complex a, complex b)
{
realPart = a.realPart * b.realPart;
imaginaryPart = a.imaginaryPart * b.imaginaryPart;
}
public static complex operator *(complex a, complex b)
{
complex c = new complex();
c.realPart = a.realPart * b.realPart;
c.imaginaryPart = a.imaginaryPart * b.imaginaryPart;
return c;
}
public static complex operator /(complex a, complex b)
{
complex c = new complex();
c.realPart = (a.realPart * b.realPart + a.realPart * (-b.imaginaryPart)) + (a.imaginaryPart * b.realPart + a.imaginaryPart * (-b.imaginaryPart));
c.imaginaryPart = (b.realPart * b.realPart + b.realPart * (-b.imaginaryPart)) + (b.imaginaryPart * b.realPart + b.imaginaryPart * (-b.imaginaryPart));
return c;
}
public static bool operator ==(complex a, complex b)
{
if (a.realPart == b.realPart&& a.imaginaryPart == b.imaginaryPart)
return true;
else
return false;
}
public static bool operator !=(complex a, complex b)
{
if (a.realPart != b.realPart && a.imaginaryPart != b.imaginaryPart)
return true;
else
return false;
}
}