-
-
[旧帖] [求助]C#写一个复数算法 0.00雪花
-
发表于: 2011-4-30 19:32 844
-
要写出类,
算法
包括加减乘除发
要重载
我钱啦前面一部分,
但后面不知道怎么写啦~
class Complex
{
private double _a;
public double A
{
get { return _a; }
set { _a = value; }
}
private double _b;
public double B
{
get { return _b; }
set { _b = value; }
}
public Complex()
{
A = 0;
B = 0;
}
public Complex(double a,double b)
{
A = a;
B = b;
}
public string showComplex()
{
return "(" + A + "," + B + ")";
}
//模
public double Module()
{
return Math.Sqrt(A * A + B * B);
}
//加法
public Complex Addition(double a, double b)
{
A += a;
B += b;
return this;
}
public Complex Addition(Complex c)
{
A += c.A;
B += c.B;
return this;
}
public Complex Addition(double a)
{
A += a;
return this;
}
//减法
public Complex Subtraction(double a, double b)
{
A -= a;
B -= b;
return this;
}
public Complex Subtraction(Complex c)
{
A -= c.A;
B -= c.B;
return this;
}
public Complex Subtraction(double a)
{
A -= a;
return this;
}
//乘法
public Complex Multiplication(double a, double b)
{
double x = A, y = B;
A = x * a - y * b;
B = y * a + x * b;
return this;
}
public Complex Multiplication(Complex c)
{
double x = A, y = B;
A = x * c.A - y * c.B;
B = y * c.A + x * c.B;
return this;
}
public Complex Multiplication(double a)
{
A = A * a;
B = B * a;
return this;
}
//除法:
public Complex Division(double a, double b)
{
double x = A, y = B;
A = (x * a + y * b) / (x * x + y * y);
B = (x * b - a * y) / (x * x + y * y);
return this;
}
public Complex Division(Complex c)
{
double x = A, y = B;
A = (x * c.A + y * c.B) / (x * x + y * y);
B = (x * c.B - c.A * y) / (x * x + y * y);
return this;
}
public Complex Division(double a)
{
A = a / A;
B = B / A;
return this;
}
}
static void Main(string[] args)
{
Complex c1 = new Complex();
Console.WriteLine(c1.showComplex());
Complex c2 = new Complex(1, 2);
Console.WriteLine(c2.showComplex());
Console.WriteLine("c2的模为:{0}", c2.Module());
Complex c3 = new Complex();
Console.WriteLine("c3与1+2的和为:{0}",c3.ToString());
Console.ReadLine();
}
求高手帮助~
算法
包括加减乘除发
要重载
我钱啦前面一部分,
但后面不知道怎么写啦~
class Complex
{
private double _a;
public double A
{
get { return _a; }
set { _a = value; }
}
private double _b;
public double B
{
get { return _b; }
set { _b = value; }
}
public Complex()
{
A = 0;
B = 0;
}
public Complex(double a,double b)
{
A = a;
B = b;
}
public string showComplex()
{
return "(" + A + "," + B + ")";
}
//模
public double Module()
{
return Math.Sqrt(A * A + B * B);
}
//加法
public Complex Addition(double a, double b)
{
A += a;
B += b;
return this;
}
public Complex Addition(Complex c)
{
A += c.A;
B += c.B;
return this;
}
public Complex Addition(double a)
{
A += a;
return this;
}
//减法
public Complex Subtraction(double a, double b)
{
A -= a;
B -= b;
return this;
}
public Complex Subtraction(Complex c)
{
A -= c.A;
B -= c.B;
return this;
}
public Complex Subtraction(double a)
{
A -= a;
return this;
}
//乘法
public Complex Multiplication(double a, double b)
{
double x = A, y = B;
A = x * a - y * b;
B = y * a + x * b;
return this;
}
public Complex Multiplication(Complex c)
{
double x = A, y = B;
A = x * c.A - y * c.B;
B = y * c.A + x * c.B;
return this;
}
public Complex Multiplication(double a)
{
A = A * a;
B = B * a;
return this;
}
//除法:
public Complex Division(double a, double b)
{
double x = A, y = B;
A = (x * a + y * b) / (x * x + y * y);
B = (x * b - a * y) / (x * x + y * y);
return this;
}
public Complex Division(Complex c)
{
double x = A, y = B;
A = (x * c.A + y * c.B) / (x * x + y * y);
B = (x * c.B - c.A * y) / (x * x + y * y);
return this;
}
public Complex Division(double a)
{
A = a / A;
B = B / A;
return this;
}
}
static void Main(string[] args)
{
Complex c1 = new Complex();
Console.WriteLine(c1.showComplex());
Complex c2 = new Complex(1, 2);
Console.WriteLine(c2.showComplex());
Console.WriteLine("c2的模为:{0}", c2.Module());
Complex c3 = new Complex();
Console.WriteLine("c3与1+2的和为:{0}",c3.ToString());
Console.ReadLine();
}
求高手帮助~
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
赞赏
他的文章
- [求助]求一个ASP.NET的考勤系统 971
- [求助]求高手用JAVA写一个抽奖程序。 961
- [求助]C#写一个复数算法 845
- [求助]C#编程问题 964
- [求助]求C语言高手帮忙~ 1707
看原图
赞赏
雪币:
留言: