#include<iostream>
#include<stdlib.h>
using namespace std;
class Complex
{
public:
Complex(float r=0,float i =0):_r(r),_i(i)
{
}
void print() const
{
cout<<" _r "<<_r<<" _i "<<_i<<endl;
}
private:
float _r;
float _i;
public:
const Complex& operator+=(const Complex & y);
const Complex& operator-=(const Complex & y);
const Complex& operator*=(const Complex & y);
const Complex& operator/=(const Complex & y);
const Complex operator-(const Complex & y);
const Complex operator+(const Complex & y);
const Complex Complex::operator--();
const bool operator==(const Complex & y);
const bool operator!=(const Complex & y);
};
inline const Complex Complex::operator-(const Complex & y)
{
Complex c;
c._r=_r-y._r;
c._i=_i-y._i;
return c;
}
inline const Complex Complex::operator--()
{
_r=_r-1;
_i=_i-1;
return *this;
}
inline const bool Complex::operator==(const Complex & y)
{
bool b=true;
if((*this)._r!=y._r||(*this)._i!=y._i)
b=false; return b;
}
inline const bool Complex::operator!=(const Complex & y)
{
bool b=true;
if((*this)._r==y._r&&(*this)._i==y._i)
b=false; return b; }
inline const Complex Complex::operator+(const Complex & y)
{
Complex c;
c._r=_r+y._r;
c._i=_i+y._i;
return c;
}
inline const Complex& Complex::operator+=(const Complex & y)
{
_r=_r+y._r;
_i=_i+y._i;
return *this;
}
inline const Complex& Complex::operator-=(const Complex & y)
{
*this=*this-y;
return *this;
}
inline const Complex& Complex::operator*=(const Complex & y)
{
_r=_r*y._r-_i*y._i;
_i=_r*y._i+_i*y._r;
return *this;
}
inline const Complex& Complex::operator/=(const Complex & y)
{
if(y._r==0 && y._i==0)
{
exit(1);
}
float den=_r*y._r+_i*y._i;
_r=(_r*y._r+_i*y._i)/den;
_i=(_i*y._r-_r*y._i)/den;
return *this;
}
int main()
{
Complex x(2,3),y(-1,3);
cout<<" x is ";
x.print();
cout<<" y is ";
y.print(); (x+=y).print();
x.operator+=(y).print();
(x-=y).print();
x.operator-=(y).print();
(x*=y).print();
x.operator*=(y).print();
(x/=y).print();
x.operator/=(y).print(); cout<<(x==y)<<endl;
cout<<(x!=y)<<endl;
return 0; }

最新文章

  1. [HTML5] Blob对象
  2. java 数据类型
  3. paip.杀不死进程的原因--僵尸进程的解决.txt
  4. Creater中选择一行的方法
  5. cookie ,session Storage, local storage
  6. HTML要点(五)&lt;iframe&gt;标签
  7. 1.4.10 Schemaless模式
  8. Mysql笔记【2】-数据表的基本操作
  9. (2015年郑州轻工业学院ACM校赛题)H 五子棋
  10. C# 方法的可选参数、命名参数
  11. java中接口实现多态举例
  12. [SDOI2018] 战略游戏
  13. 斯坦福大学公开课机器学习:advice for applying machine learning - deciding what to try next(设计机器学习系统时,怎样确定最适合、最正确的方法)
  14. luogu P3241 [HNOI2015]开店
  15. 第七十五课 图的遍历(DFS)
  16. 细看Thread的 start() 和 run()方法
  17. Java之装饰模式
  18. Kaggle大数据竞赛平台入门
  19. SqlServer中 CREATE PARTITION FUNCTION使用
  20. Revit API根据参数类型取得参数的值

热门文章

  1. 018如何建立自动化框架 how to bulid the framwork
  2. 关于photoshop钢笔工具中各点对应到“贝塞尔曲线”中的含义(cocos2d-x与iOS)
  3. 线性存储结构-Stack
  4. 用JSP做后台管理系统
  5. java 实现死锁
  6. C++空类以及没有成员变量的类的大小
  7. python 网络编程(四)---UDP服务端客户端
  8. 【暑假】[深入动态规划]UVa 10618 The Bookcase
  9. mvc5入门,经典教程。。
  10. 4.3 Reduction代码(Heterogeneous Parallel Programming class lab)