用c++实现加法器
2017-01-23 20:44
375 查看
#include <iostream> using namespace std; class complex{ private: double real; //实部 double imag; //虚部 public: complex(): real(0.0), imag(0.0){ } complex(double a, double b): real(a), imag(b){ } complex operator+(const complex & A)const; void display()const; }; //运算符重载 complex complex::operator+(const complex & A)const{ complex B; B.real = real + A.real; B.imag = imag + A.imag; return B; } void complex::display()const{ cout<<real<<" + "<<imag<<"i"<<endl; } int main(){ complex c1(4.3, 5.8); complex c2(2.4, 3.7); complex c3; c3 = c1 + c2; c3.display(); return 0; }
相关文章推荐
- 用c++实现加法器
- c++实现加法器
- 在C++中实现“属性 (Property)”
- 在Delphi与C++之间实现函数与对象共享
- C++机理:虚拟机制的实现[兼谈对比于传统机制]
- 用C++ std::priority_queue 实现哈夫曼算法
- 用C++实现C#中的委托/事件(标准C++之升级版)
- 用 C++ 实现 C# 中的 委托/事件 (2-delegate event functor)
- 在C++中实现属性
- 用PHP实现通过Web执行C/C++程序
- 使用c++实现Format函数
- 在Delphi与C++之间实现函数与对象共享
- 分析模式-计量的C++实现——完美版本
- Singleton模式的C++实现研究(转贴)
- C++设计模式:Singleton的模板实现之一
- C++实现单件的初探
- 单件模式的C++模板实现
- 分析模式-计量的C++实现——回复ch0877
- 小写转大写金额在C++中的实现
- 用 C++ 实现 C# 中的 委托/事件 (5-functor2)