One of my Java jobs, I changed it to ASP.net (C #).
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
Complex complex_a = new Complex (1.0, 1.0);
Complex Complex_b = new Complex (2.0, 2.0);
Response.Write ("Addition operation result:" + complex_a.complex_add (Complex_b). ToString () + "<br/>");
Response.Write ("Subtraction Result:" + Complex_a.complex_minus (Complex_b). ToString () + "<br/>");
Response.Write ("Multiplication Result:" + complex_a.complex_multi (Complex_b). ToString () + "<br/>");
Response.Write ("Division operation result:" + complex_a.complex_divide (Complex_b). ToString ());
}
Design by Ahanan from: Search bar sosuo8.com
public class Complex
{
The real part in the plural
Private double complex_real;
Imaginary part in a complex number
Private double complex_imagin;
Constructors
Public complex (double R, double i)
{
Complex_real = R;
Complex_imagin = i;
}
Overriding the ToString () method
public override string ToString ()
{
return this.complex_real + "+" + this.complex_imagin + "I";
}
Complex number addition operation
Public complex Complex_add (complex c)
{
Get the real part after the addition operation
Double complex_real = this.complex_real + c.complex_real;
To obtain the imaginary part after the addition operation
Double Complex_imagin = This.complex_imagin + c.complex_imagin;
Returns a complex number class
return new complex (Complex_real,complex_imagin);
}
Complex subtraction operation
Public complex Complex_minus (complex c)
{
Gets the real part after the subtraction operation
Double complex_real = this.complex_real-c.complex_real;
To obtain the imaginary part after the subtraction operation
Double complex_imagin = This.complex_imagin-c.complex_imagin;
Returns a complex number class
return new Complex (Complex_real, complex_imagin);
}
Multiplication operations
Public complex Complex_multi (complex c)
{
Get the real part after the multiplication operation
Double complex_real = this.complex_real * C.complex_real-this.complex_imagin * c.complex_imagin;
To obtain the imaginary part after multiplication operation
Double Complex_imagin = this.complex_real * c.complex_imagin + this.complex_imagin * c.complex_real;
Returns a complex number class
return new Complex (Complex_real, complex_imagin);
}
Division result (A+BI)/(C+di) = (A+bi) (C-di)/(C+di) (C-di)
Public complex Complex_divide (complex c)
{
Gets the value of (C+di) (C-di)
Double d = c.complex_real * c.complex_real + c.complex_imagin * c.complex_imagin;
Get the real part after the division operation
Double complex_real = (This.complex_real * c.complex_real + this.complex_imagin * c.complex_imagin)/D;
To obtain the imaginary part after division operation
Double Complex_imagin = (This.complex_real * (-c.complex_imagin) + this.complex_imagin * c.complex_real)/D;
Returns a complex number class
return new Complex (Complex_real, complex_imagin);
}
}
Run Result:
Copy Code code as follows:
addition operation result:3+3i
Subtraction result:-1+-1i
Multiplication Result: 0+4i& nbsp;
Division results:0.5+0i