复数类实现
来源:互联网 发布:织梦cms和wordpress 编辑:程序博客网 时间:2024/06/06 07:47
复数类实现
实现复数类的++、–、+、-、比较大小等
1.#include <iostream>
2.using namespace std;
3.
4.class Complex
5.{
6.public:
7. Complex(double real = 0.0, double image = 0.0)
8. :_real(real)
9. ,_image(image)
10. {
11. }
12.
13. Complex(const Complex& d)
14. :_real(d._real)
15. ,_image(d._image)
16. {
17. }
18. ~Complex()
19. {
20. }
21.
22. Complex& operator=(const Complex& d)
23. {
24. _real = d._real;
25. _image = d._image;
26. return *this;
27. }
28.
29. void Display()
30. {
31. cout<<"_real=="<<_real<<"_image=="<<_image<<endl;
32. }
33.
34. bool operator>(const Complex& d)const
35. {
36. if((_real > d._real)&&(_image > d._image))
37. return true;
38. return false;
39. }
40.
41. bool operator<(const Complex& d)const
42. {
43. if((_real < d._real)&&(_image < d._image))
44. return true;
45. return false;
46. }
47.
48. bool operator>=(const Complex& d)const
49. {
50. if(this < &d)
51. return false;
52. return true;
53. }
54.
55. bool operator<=(const Complex& d)const
56. {
57. if(this > &d)
58. return false;
59. return true;
60. }
61.
62. bool operator==(const Complex& d)const
63. {
64. if((_real == d._real)&&(_image == d._image))
65. return true;
66. return false;
67. }
68. bool operator!=(const Complex& d)const
69. {
70. if(this == &d)
71. return false;
72. return true;
73. }
74.
75. Complex& operator++()//(前置++)复数++只给实部+
76. {
77. _real++;
78. return *this;
79. }
80.
81. Complex& operator++(int)//后置++
82. {
83. Complex tmp = *this;
84. tmp._real++;
85. return *this;
86. }
87.
88. Complex& operator+=(const Complex& d)
89. {
90. _real += d._real;
91. return *this;
92. }
93.
94. Complex& operator+(const Complex& d)
95. {
96. _real + d._real;
97. return *this;
98. }
99.
100.private:
101. double _real;
102. double _image;
103.};
104.
105.
106.int main()
107.{
108. Complex d1(2.3,3.2);
109. Complex d2;
110. d2 = d1;
111. d2.Display();
112. system("pause");
113. return 0;
114.}
115.
116.
阅读全文
0 0
- C++实现复数类
- 复数类的实现
- c++实现复数类
- C++实现 复数类
- 复数类的实现
- C++实现复数类
- 复数类实现
- 复数类的实现
- 【C++】实现复数类
- 实现一个复数类
- 复数类的JAVA实现
- 复数类[一]----C#实现
- C# 实现 复数 运算 类
- 简单的实现复数类
- Java 复数类 实现加减乘除
- 复数类的简单实现
- 【c++】实现一个复数类
- [c++]复数类的实现
- java方法的理解、调用栈与异常处理
- 【51Nod】1106 质数检测
- 【HTML5学习笔记】18:CSS颜色和度量单位
- 服务器反向代理中用于存放客户端原始 IP 地址
- Qt之界面数据存储与获取(使用setUserData()和userData())
- 复数类实现
- Android—数据存储方式(一)
- JAVASE基础(三)
- block用copy修饰,delegate 用weak修饰,
- Mybatis的<where><foreach><set>等标签详解
- 使ListView与GridView无滚动效果,使其能与ScrollView兼容
- mysql安装
- (1-1)Unity3D/2D:创建Sprite游戏对象
- python数据处理