下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本文格式为Word版,下载可任意编辑——C大学教程第11章试验报告姓名:班级:计科1203日期:2023.11.24学号:试验四(11.13、11.14、11.17)
试验1Complex运算符重载1.代码实现:
//Complex.h
#include//usingstd::ostream;//usingstd::istream;ClassComplex{friendstd::ostreamfriendstd::istreampublic:Complex(double=0.0,double=0.0);Complexoperator+(constComplexComplexoperator-(constComplexComplexoperator*(constComplexbooloperator==(constComplex
booloperator!=(constComplex}private:doublereal;doubleimaginary;};
//类成员函数Complex.cpp
#includeusingstd::setw;
#include\
Complex::Complex(doublerealPart,doubleimaginaryPart):real(realPart),
imaginary(imaginaryPart){}
ComplexComplex::operator+(constComplex}
ComplexComplex::operator-(constComplex}
ComplexComplex::operator*(constComplex}
boolComplex::operator==(constComplex}
std::istreaminput>>setw(3)>>c.real;input.ignore(2);
input>>setw(3)>>c.imaginary;returninput;}
std::ostream}
//测试函数testComplex.cpp#includeusingstd::endl;usingstd::cout;
#include\intmain(){
Complexx;
Complexy(4.3,8.2);Complexz(3.3,1.1);Complexw(4.3,8.2);
coutusingstd::ostream;classHugeInt{
friendostreampublic:
HugeInt(long=0);
HugeInt(constchar*);
HugeIntoperator+(constHugeInt//HugeInt+HugeIntHugeIntoperator+(int)const;//HugeInt+int
HugeIntoperator+(constchar*)const;//HugeInt+string
HugeIntoperator*(constHugeIntHugeIntoperator*(int)const;
HugeIntoperator*(constchar*)const;HugeIntoperator(HugeIntbooloperator=(HugeIntintgetLength()const;private:
shortinteger[30];};#endif
//成员函数Hugeint.cpp#includeusingstd::cout;usingstd::endl;#include
usingstd::isdigit;//判断字符是否为数字#include#include\
HugeInt::HugeInt(longvalue){
for(inti=0;i=0;i--){
eger[i]=integer[i]+eger[i]+carry;if(eger[i]>9){
eger[i]%=10;carry=1;}else
carry=0;}
returntemp;}
HugeIntHugeInt::operator+(intop2)const{
return*this+HugeInt(op2);}
HugeIntHugeInt::operator+(constchar*op2)const{
return*this+HugeInt(op2);}
HugeIntHugeInt::operator*(constHugeIntintcarry2=0;for(inti=29;i>=29-getLength();i--){HugeInttemp(\for(intj=29;j>=29-op2.getLength();j--){eger[j]=(integer[i]*eger[j]%10+carry1+carry2)%10;carry1=integer[i]*eger[j]/10;carry2=(integer[i]*eger[j]%10+carry1+carry2)/10;}TEMP=(temp(HugeInt}
boolHugeInt::operator>=(HugeInt}
ostream(eger[i]==0)i++);
if(i==30)outputusingstd::cout;usingstd::endl;
#include\intmain(){
HugeIntn1(7654321);HugeIntn2(7891234);
HugeIntn3(\HugeIntn4(\HugeIntn5;
coutn2)
cout=n2)
coutusingstd::cin;usingstd::cout;usingstd::endl;
#include
usingstd::showpos;//能让输出的正数前带正号usingstd::noshowpos;//让输出的负数前带负号#include\Polynomial::Polynomial(){for(intt=0;t>length;
for(intn=1;n>c;
cout
{*this=*this*r;return*this;}
Polynomial::~Polynomial(){}
//测试函数testPolynom
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 餐饮系列研究之茶饮+咖啡深度:外卖大战后的变与不变
- 2025江西省电子商务高级技工学校工作人员招聘考试试题
- 2025汉中市第一职业中等专业学校工作人员招聘考试试题
- 胰岛β细胞功能的调控机制与损伤机制总结2026
- 大型塔吊安拆施工方案
- 初中数学建模思想在物流优化中的应用课题报告教学研究课题报告
- 新型阻燃涂料在防火涂料行业中的应用前景与市场潜力教学研究课题报告
- 2026年日化包装包装设计美学创新报告
- 幼儿园教师观察记录工具使用熟练度影响-基于观察记录质量与培训记录关联
- 2026年通信行业5G应用创新与发展报告
- 2026眼镜镜片制造过程评估及镀膜工艺Plus偏光镜研发趋势说明
- 2026-2030中国摩卡咖啡壶行业市场发展趋势与前景展望战略分析研究报告
- (新)生物安全年度工作计划
- 员工雇佣合同
- 5.1.4 识读识读预焙阳极铝电解槽的结构图
- (高清版)DZT 0426-2023 固体矿产地质调查规范(1:50000)
- 多式联运应用及其优势分析
- 道路照明计算中海创
- 酒店西餐厅工作程序SOP
- GB/T 25916.2-2010洁净室及相关受控环境生物污染控制第2部分:生物污染数据的评估与分析
- GB/T 19587-2017气体吸附BET法测定固态物质比表面积
评论
0/150
提交评论