设为首页 加入收藏

TOP

c++中的messagebox()用法(一)
2013-07-23 09:10:56 来源: 作者: 【 】 浏览:835
Tags:messagebox 用法

  用类的成员函数完成运算符的重载的代码如下,请大家自己调试:

  #include

  using namespace std;

  class Complex

  {public:

  Complex(){real=0;imag=0;}

  Complex(double r,double i){real=r;imag=i;}

  Complex operator+(Complex &c2);

  Complex operator-(Complex &c2);

  Complex operator*(Complex &c2);

  Complex operator/(Complex &c2);

  void display();

  private:

  double real;

  double imag;

  };

  Complex Complex::operator+(Complex&c2)

  {

  return Complex(real+c2.real,imag+c2.imag);

  }

  Complex Complex::operator-(Complex&c2)

  {

  return Complex(real-c2.real,imag-c2.imag);

  }

  Complex Complex::operator*(Complex&c2)

  {

  return Complex(real*c2.real+imag*c2.imag,real*c2.imag+imag*c2.real);

  }

  Complex Complex::operator/(Complex&c2)

  {

  return Complex((real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag),(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag));

  }

   

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++流操作之fstream 下一篇大数处理之进制转换

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: