I wrote a Java job into Asp.net (C #).
CopyCode The Code is 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 Calculation Result:" + complex_a.complex_add (complex_ B). tostring () + "<br/> ");
Response. Write ("subtraction Calculation Result:" + complex_a.complex_minus (complex_ B). tostring () + "<br/> ");
Response. Write ("Multiplication Result:" + complex_a.complex_multi (complex_ B). tostring () + "<br/> ");
Response. Write ("Division calculation result:" + complex_a.complex_divide (complex_ B). tostring ());
}
// Design by ayunan: Search for sosuo8.com
Public class Complex
{
// Real part in the plural
Private double complex_real;
// Imaginary part in the plural number
Private double complex_imagin;
// Constructor
Public complex (Double R, double I)
{
Complex_real = R;
Complex_imagin = I;
}
// Rewrite the tostring () method
Public override string tostring ()
{
Return this. complex_real + "+" + this. complex_imagin + "I ";
}
// Add multiple numbers
Public complex complex_add (Complex C)
{
// Obtain the real part after the addition operation
Double complex_real = This. complex_real + C. complex_real;
// Obtain the virtual part after the addition operation
Double complex_imagin = This. complex_imagin + C. complex_imagin;
// Return a plural class
Return new complex (complex_real, complex_imagin );
}
// Complex Subtraction
Public complex complex_minus (Complex C)
{
// Obtain the real part after the subtraction operation
Double complex_real = This. complex_real-C. complex_real;
// Obtain the virtual part after the subtraction operation
Double complex_imagin = This. complex_imagin-C. complex_imagin;
// Return a plural class
Return new complex (complex_real, complex_imagin );
}
// Multiplication
Public complex complex_multi (Complex C)
{
// Obtain the real part after Multiplication
Double complex_real = This. complex_real * C. complex_real-This. complex_imagin * C. complex_imagin;
// Obtain the imaginary part after Multiplication
Double complex_imagin = This. complex_real * C. complex_imagin + this. complex_imagin * C. complex_real;
// Return a plural class
Return new complex (complex_real, complex_imagin );
}
// Division calculation result (a + bi)/(C + DI) = (a + bi) (C-DI)/(C + DI) (C-DI)
Public complex complex_divide (Complex C)
{
// Obtain the value of (C + DI) (C-DI)
Double D = C. complex_real * C. complex_real + C. complex_imagin * C. complex_imagin;
// Obtain the real part after division.
Double complex_real = (this. complex_real * C. complex_real + this. complex_imagin * C. complex_imagin)/d;
// Obtain the virtual part after division.
Double complex_imagin = (this. complex_real * (-C. complex_imagin) + this. complex_imagin * C. complex_real)/d;
// Return a plural class
Return new complex (complex_real, complex_imagin );
}
}
Running result:
Copy code The Code is as follows: Addition Calculation Result: 3 + 3I
Subtraction result:-1 +-1i
Multiplication result: 0 + 4I
Division calculation result: 0.5 + 0i