作业_复数类的参考代码

作业_复数类的参考代码

ID:41420263

大小:59.92 KB

页数:8页

时间:2019-08-24

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

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

1、#includeusingstd::ostream;classComplex{private:doublereal,image;public:Complex(doublerl=0,doubleimg=O):real(rl),image(img){}Complex(constComplex&c):real(c.real),image(c.image)}}doubleReal()const{returnreal;)doubleImage()const{returnimage;}voidReal(doubleii){real=r

2、l;}voidImage(doubleimg){image=img;}voidSet(doublex,doubley){real=x;image=y;}Complexoperator+(constComplex&c2)const;Complexoperator-(constComplex&c2)const;Complexoperator*(constComplex&c2)const;Complexoperator/(constComplex&c2)const;voidPrint()const;friendostream&opcrat(”vv(

3、ostrcam&out,constComplex&c);#endiflllllllllllllllllllllllllllllllllllllllll//Complex.CPPlllllllllllllllllllllllllllllllllllllllll#include#include"Complex.h”usingnamespacestd;ostream&openitoKvCostream&out,constComplex&c){c.Print();returnout;}voidComplex::Print()con

4、st{if(image==0){cout«real;}elseif(real==0){cout«image«T;}elseif(image>0){coinvv(vvrcalvv'+NvimagcvvTvv'):elseif(image<0)coutvvY'vvrealvvimagevvTvv')';ComplexComplex::operator+(constComplex&c2)const{Complexret;ret.Set(c2.real+reahc2.image+image);returnret;}ComplexComplex::op

5、crator-(constComplex&c2)constComplexComplex::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::operator/(constComplex&c2)const{doublem=c2.real*c2.re

6、al+c2.image*c2.image;doublex=(real*c2・real+image*c2・image)/m;doubley=(image*c2.real-real*c2.image)/m;returnComplex(x,y);lllllllllllllllllllllllllllllllllllllllllIITcst.hIllllllllllllllllllllllllllllllllllllllll#ifndefTEST_H#defineTEST_H//=====================voidTest_l();vo

7、idTest_l_l();voidTest_l_2();voidTest_2();voidTest_3();voidTest_4();voidTcst_4_l();voidTest_5();//=====================#endiflllllllllllllllllllllllllllllllllllllllll//Test.CPPlllllllllllllllllllllllllllllllllllllllll#include#include#include"Complex.h"usin

8、gnamespacestd;voidTest_l(){//测试当复数退化为实数时的四则运算coutvvT.O测试当复数退化为实数时的四则运算”vvendl;Comp

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

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

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