求一题的完整代码?谢过。

nsq0205 2010-04-07 09:31:49
设计complex类,完成复数的+、-、*、/运算。
...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
缭绕飘渺 2010-04-09
  • 打赏
  • 举报
回复
这是数学问题
你要了解复数的-,*,/这些操作是怎样进行的
实部和虚部各是怎样处理的
然后仿照+的算法写不就完了吗
xray2005 2010-04-08
  • 打赏
  • 举报
回复
public struct Complex
{
public int real;
public int imaginary;

public Complex(int real, int imaginary) //constructor
{
this.real = real;
this.imaginary = imaginary;
}

// Declare which operator to overload (+),
// the types that can be added (two Complex objects),
// and the return type (Complex):
public static Complex operator +(Complex c1, Complex c2)
{
return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
}

// Override the ToString() method to display pointA complex number in the traditional format:
public override string ToString()
{
return (System.String.Format("{0} + {1}radius", real, imaginary));
}
}

MSDN上+的例子
nsq0205 2010-04-08
  • 打赏
  • 举报
回复
+的算法我知道,其他的我就不知道了!
Alden 2010-04-08
  • 打赏
  • 举报
回复
自己研究研究表达式解析,一般主要用后缀表达式.
如果转化为后缀表达式后,结果也就出来了,关键是你如何转化中缀表达式为后缀表达式.
参照这个看看:
http://baike.baidu.com/view/339689.htm?fr=ala0_1_1

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧