作业·复数类的参考代码

作业·复数类的参考代码

ID:17909320

大小:45.50 KB

页数:4页

时间:2018-09-09

作业·复数类的参考代码_第1页
作业·复数类的参考代码_第2页
作业·复数类的参考代码_第3页
作业·复数类的参考代码_第4页
资源描述:

《作业·复数类的参考代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、复数类的参考代码(功能不完整,有待补充

2、

3、VC++2005编译测试)///////////////////////////////////////////Complex.h/////////////////////////////////////////#ifndefCOMPLEX_H#defineCOMPLEX_H//============================================#includeusingstd::ostream;classComplex{private:doublereal,image;

4、public:Complex(doublerl=0,doubleimg=0):real(rl),image(img){}Complex(constComplex&c):real(c.real),image(c.image){}doubleReal()const{returnreal;}doubleImage()const{returnimage;}voidReal(doublerl){real=rl;}voidImage(doubleimg){image=img;}voidSet(doublex,doubley){real=x;image=y;}Com

5、plexoperator+(constComplex&c2)const;Complexoperator-(constComplex&c2)const;Complexoperator*(constComplex&c2)const;Complexoperator/(constComplex&c2)const;voidPrint()const;friendostream&operator<<(ostream&out,constComplex&c);};//============================================#endif//

6、/////////////////////////////////////////Complex.CPP/////////////////////////////////////////#include#include"Complex.h"usingnamespacestd;ostream&operator<<(ostream&out,constComplex&c){c.Print();returnout;}voidComplex::Print()const{if(image==0){cout<

7、=0){cout<0){cout<<'('<

8、

9、VC++2005编译测试){cout<<'('<

10、Complex::operator-(constComplex&c2)const{returnComplex(real-c2.real,image-c2.image);}ComplexComplex::operator*(constComplex&c2)const{Complexret;ret.real=this->real*c2.real-this->image*c2.image;ret.Image(this->Real()*c2.Image()+this->image*c2.Real());returnret;}ComplexComplex::op

11、erator/(constComplex&c2)const{doublem=c2.real*c2.real+c2.image*c2.image;doublex=(real*c2.real+image*c2.image)/m;doubley=(image*c2.real-real*c2.image)/m;returnComplex(x,y);}///////////////////////////////////////////Test.h/////////////////////////////////////////#ifndefTEST_H#def

12、ineTEST_H//=====================voidTest_1();vo

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。