最新c++复数加减乘除的实现.doc
《最新c++复数加减乘除的实现.doc》由会员分享,可在线阅读,更多相关《最新c++复数加减乘除的实现.doc(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精品资料c+复数加减乘除的实现.c+复数加减乘除的实现c+复数加减乘除的实现C+复数加减乘除的实现#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 di
2、splay(); private: double real; double imag; ;Complex Complex:operator+(Complex &c2)Complex c; c.real=real+c2.real; c.imag=imag+c2.imag; return c;Complex Complex:operator-(Complex &c2)Complex c; c.real=real-c2.real; c.imag=imag-c2.imag; return c;Complex Complex:operator*(Complex &c2)Complex c; c.real
3、=real*c2.real-imag*c2.imag; c.imag=imag*c2.real+real*c2.imag; return c;Complex Complex:operator/(Complex &c2)Complex c; c.real=(real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); c.imag=(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); return c;void Complex:display()cout(real,imagi)endl;int main()Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; coutc1+c2=; c3.display(); c3=c1-c2; coutc1-c2=; c3.display(); c3=c1*c2; coutc1*c2=; c3.display(); c3=c1/c2; coutc1/c2=; c3.display(); return 0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新 c+ 复数 加减乘除 实现
限制150内