c++小型复数计算器

c++小型复数计算器

ID:23705486

大小:76.68 KB

页数:12页

时间:2018-11-10

c++小型复数计算器_第1页
c++小型复数计算器_第2页
c++小型复数计算器_第3页
c++小型复数计算器_第4页
c++小型复数计算器_第5页
资源描述:

《c++小型复数计算器》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、#include#include#include#include#include#include#defineEPS1e-5//定义精度常数usingnamespacestd;//使用标准空间命名stdnamespaceNameCComplex//定义命名空间NameCComplex{classCComplex////定义一个CComplex类{private:doubleReal,Image;public:CComplex(doublereal=0,

2、doubleimage=0)//构造函数{Real=real;Image=image;}friendistream&operator>>(istream&is,CComplex&com);//重载输入friendostream&operator<<(ostream&os,CComplex&com);//重载输出CComplexoperator+(CComplex&com);//加法重载CComplexoperator-(CComplex&com);//减法重载CComplexoperator*(CComplex&com);//乘法重载CComplexo

3、perator+=(CComplex&com);//加法赋值重载CComplexoperator-=(CComplex&com);//减法赋值重载CComplexoperator*=(CComplex&com);//乘法赋值重载CComplexoperator++();//自加CComplexoperator--();//自减doublemod(void);//求复数的模intoperator>(CComplex&com);intoperator<(CComplex&com);intoperator!=(CComplex&com);intoperato

4、r==(CComplex&com);};structUser//用户结构体类型定义{charszName[20];//用户名intnTime;//使用次数intnTest;//测试次数doublealAve;//平均成绩intnAdd;//加法次数intnSub;//减法次数intnMul;//乘法次数doubledlScore[3];//3次测试得分}user;//定义全局变量CComplexCComplex::operator++()//重载运算符"++",实部与虚部均加1{Real++;Image++;return*this;}CComplexC

5、Complex::operator--()//重载运算符"--",实部与虚部均减1{Real--;Image--;return*this;}doubleCComplex::mod()//求复数的模的平方,返回实部^2+虚部^2{returnReal*Real+Image*Image;}intCComplex::operator>(CComplex&com)//重载运算符">",比较模的大小{if(mod()>com.mod())return1;elsereturn0;}intCComplex::operator<(CComplex&com){if(mo

6、d()>(istream&is,CComplex&com)//重载输入,可以输入a+bi的形式{cout<<"请输入复数:";chars[80];is>>s;//用字符串的形式接受复数intlen=strlen(s);//求出字符串的长度intn=

7、0,sign=1;//n为当前从字符串中提取出来的数字,初始化为0;sign是难道符号,初始化为正com.Image=com.Real=0;for(intk=0;k

8、

9、s[k]>'9')&&(s[k]!='+'&&s[k]!='-'&&s[k]!='i')){cout<<"error"<

10、

11、s[k]=='+'))//当前字符是

12、否是符号位{com.Real=sign*n;//是符号位,且n!=0,即n已被赋值,表明当前读

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

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

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