C大学教程第11章试验报告_第1页
C大学教程第11章试验报告_第2页
C大学教程第11章试验报告_第3页
C大学教程第11章试验报告_第4页
C大学教程第11章试验报告_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论