c++运算符重载习题

合集下载

c 运算符的重载习题答案

c  运算符的重载习题答案

1.概念填空题1.1运算符重载是对已有的运算符赋予多重含义,使同一个运算符在作用于不同类型对象时导致不同的行为。

运算符重载的实质是函数重载,是类的多态性特征。

1.2可以定义一种特殊的类型转换函数,将类的对象转换成基本数据类型的数据。

但是这种类型转换函数只能定义为一个类的成员函数而不能定义为类的友元函数。

类类型转换函数既没有参数,也不显式给出返回类型。

类类型函数中必须有return 表达式的语句返回函数值。

一个类可以定义多个类类型转换函数。

1.3运算符重载时其函数名由operator运算符构成。

成员函数重载双目运算符时,左操作数是对象,右操作数是函数参数。

2.简答题2.2简述运算符重载的规则。

2.2简述重载单目运算符++、--,前置和后置时的差别。

2.3 C++中重运算符是否都可以重载?是否都可以重载成类的成员函数?是否都可以重载成类的友元函数?2.4 构造函数作为类型转换函数的条件是什么。

3.选择题3.1在下列运算符中,不能重载的是(B)A.!B. sizeofC. newD. delete3.2 不能用友员函数重载的是(A)。

A.=B.==C.<=D.++3.3下列函数中,不能重载运算符的函数是(B)。

A.成员函数B.构造函数C.普通函数D.友员函数3.4如果表达式++i*k时中的”++”和”*”都是重载的友元运算符,则采用运算符函数调用格式,该表达式还可表示为(B)。

A.operator*(i.operator++(),k) B.operator*(operator++(i),k)C.i.operator++().operator*(k) D.k.operator*(operator++(i))3.5已知在一个类体中包含如下函数原型:VOLUME operator-(VOLUME)const;下列关于这个函数的叙述中,错误的是(B )。

A.这是运算符-的重载运算符函数B.这个函数所重载的运算符是一个一元运算符C.这是一个成员函数D.这个函数不改变数据成员的值3.6在表达式x+y*z中,+是作为成员函数重载的运算符,*是作为非成员函数重载的运算符。

C 重载习题

C 重载习题

01.分析以下程序执行结果#include<>int add(int x,int y){return x+y;}double add(double x,double y){return x+y;}void main(){int a=4,b=6;double c=,d=;cout<<add(a,b)<<","<<add(c,d)<<endl;}解:本题说明函数重载的使用方法,这里有两个add()函数,一个add()函数的参数与返回值为int型,另一个的参数与返回值为double型,它们是根据参数类型自动区分的。

所以输出为: 10,10-----------------------------------------------02.分析以下程序的执行结果#include<>class Sample{int i;double d;public:void setdata(int n){i=n;}void setdata(double x){d=x;}void disp(){cout<<"i="<<i<<",d="<<d<<endl;}};void main(){Sample s;(10);;();}解:本题说明重载成员函数的使用方法。

setdata()成员函数有两个,根据其参数类型加以区分。

所以输出为:i=10, d=-----------------------------------------------03.分析以下程序的执行结果#include<>class Sample{int n;public:Sample(){}Sample(int i){n=i;}Sample &operator =(Sample);void disp(){cout<<"n="<<n<<endl;}};Sample &Sample::operator=(Sample s){Sample::n=;return *this;}void main(){Sample s1(10),s2;s2=s1;();}解:本题说明重载运算符(=)的使用方法。

最新《C++程序设计案例教程》习题答案第10章 运算符重载

最新《C++程序设计案例教程》习题答案第10章  运算符重载

第10章运算符重载一、选择题1.A2.D3.A4.B5.D6.C二、写出下列程序运行结果(略)三、简答题1.(1)只能重载已有的C++运算符,不可自创新的运算符。

(2)重载后运算符的优先级和结合性都不变。

(3)重载的功能应当与原有功能相类似。

2.: : . .* ? : sizeof typeid 3.&& | | ,四、编程题1.#include<iostream>class MyString{public:MyString(){strLength=0;pStr=new char[1];*pStr='\0';}MyString(const char*pString){strLength=strlen(pString);pStr=new char[strLength+1];strcpy(pStr,pString);}MyString(char ch,int n){strLength=n;pStr=new char[strLength+1];for(unsigned int i=0;i<strLength;*(pStr+i++)=ch);*(pStr+strLength)='\0';}MyString(int number){char buffer[20];int temp=number;if(number<0)number=-number;int len=0;do{buffer[len++]=static_cast<char>('0'+number%10 );number/=10;}while(number>0);if(temp<0)buffer[len++]='-';buffer[len]='\0';strLength=len;pStr=new char[strLength+1];strcpy(pStr,buffer);char ch=0;for(int i=0,j=len-1;i<j;i++,j--){ch=pStr[i];pStr[i]=pStr[j];pStr[j]=ch;}}MyString(const MyString&rString){strLength=rString.strLength;pStr=new char[strLength+1];strcpy(pStr,rString.pStr);}~MyString(){delete[]pStr;}MyString& operator+(const MyString&rStr)const {return MyString(*this)+=rStr;}};2.#include<iostream>class MyString{public:MyString(){strLength=0;pStr=new char[1];*pStr='\0';}MyString(const char*pString){strLength=strlen(pString);pStr=new char[strLength+1];strcpy(pStr,pString);}MyString(char ch,int n){strLength=n;pStr=new char[strLength+1];for(unsigned int i=0;i<strLength;*(pStr+i++)=ch);*(pStr+strLength)='\0';}MyString(int number){char buffer[20];int temp=number;if(number<0)number=-number;int len=0;do{buffer[len++]=static_cast<char>('0'+number%10 );number/=10;}while(number>0);if(temp<0)buffer[len++]='-';buffer[len]='\0';strLength=len;pStr=new char[strLength+1];strcpy(pStr,buffer);char ch=0;for(int i=0,j=len-1;i<j;i++,j--){ch=pStr[i];pStr[i]=pStr[j];pStr[j]=ch;}}MyString(const MyString&rString){strLength=rString.strLength;pStr=new char[strLength+1];strcpy(pStr,rString.pStr);}~MyString(){delete[]pStr;}MyString& Operator=(const MyString&rStr)const{if(this == &rStr)return *this;delete []str;str = new char[strlen(rStr.str )+1];strcpy(str, rStr.str);return *this;}};。

C程序设计与应用基础第三章重载习题答案

C程序设计与应用基础第三章重载习题答案

第三章重载1、请完成下列填空题1)在C++中,只能重载为类的成员函数的运算符是_=_、__[]__、__()__、__->__。

2)利用成员函数对二元运算符重载,其左操作数为___This___,右操作数为___成员函数参数___。

3)单目运算符作为类成员函数重载时___没有___的参数;双目运算符作为___类成员函数___重载时需声明其右操作数,作为___友元函数___重载时需声明全部操作数。

4)设a和b是两个整型变量,a+b表示这两个变量的和:设c和d为浮点型变量,c+d也表示这两个变量的和。

这里的运算符+具有不同的用途,这是__运算符重载___的例子。

5)重载的运算符仍然保持其原来的优先级、___结合性___和___语法结构___。

6)C++中不能重载的运算符有、__*___、___::___、___?:___和___sizof___。

2、编程题1)字符串连接需要两个操作数,即两个要被连接的字符串。

请按照以平方式实现operator +操作:string1=string2+string3答案:#include <>#include <>class String{public:String(int size=80){length=size;buf=new char[length+1];*buf='\0';}String(char *s){length=strlen(s);buf=new char[length+1];strcpy(buf,s);}String(const String& str){length=strlen;buf=new char[length+1];strcpy(buf,;}~String(){delete[]buf;}String& operator =(const String& str){length=;strcpy(buf,;return *this;}void Print(){cout<<buf<<endl;}friend String operator +(const String& str1,const String& str2){String temp(strlen+strlen+1);strcpy,;strcat,;return temp;}private:char *buf;int length;};void main(){String str1,str2("Hello,"),str3("everyone!");str1=str2+str3;();}2)给th类:class Three-d{public:Three_d(int I,int j,int k){x=I;y=j;z=k;}.Three_d()){x=0;y=0;z=0;}V oid Get(int &I,int &j,int &k({I=x;j=y;k=z;}private:int x,y,z;};针对给出的类,重载"+"、"++"与"一"运算符(只重载前缀方式即可)。

国家二级C++机试(运算符重载、模板和C++流)模拟试卷1

国家二级C++机试(运算符重载、模板和C++流)模拟试卷1

国家二级C++机试(运算符重载、模板和C++流)模拟试卷1(总分:58.00,做题时间:90分钟)一、选择题(总题数:29,分数:58.00)1.运算符重载是对已有的运算符赋予多重含义,因此( )。

(分数:2.00)A.可以对基本类型(如int类型)的数据,重新定义“+”运算符的含义B.可以改变一个已有运算符的优先级和操作数个数C.只能重载C++中已经有的运算符,不能定义新运算符√D.C++中已经有的所有运算符都可以重载解析:解析:此题考查的是运算符重载。

运算符重载是针对C++语言原有的运算符进行的,并不能创造新的运算符。

2.关于运算符重载,下列表述中正确的是( )。

(分数:2.00)A.C++已有的任何运算符都可以重载B.运算符函数的返回类型不能声明为基本数据类型C.在类型转换符函数的定义中不需要声明返回类型√D.可以通过运算符重载来创建C++中原来没有的运算符解析:解析:此题考查的是运算符重载的概念。

C++语言规定,“.”、''*''、''->*''、“::”和“?:”这五个运算符不能被重载,故选项A错误;运算符函数的返回类型由该运算符所组成的表达式的值的类型来决定,故选项B说法是错误的:运算符重载是针对原有运算符,并不能通过重载创造出新的运算符,故选项D错误。

3.通过运算符重载,可以改变运算符原有的( )。

(分数:2.00)A.操作数类型√B.操作数个数C.优先级D.结合性解析:解析:此题考查的是运算符重载。

运算符重载具有保持其原有的操作数个数、优先级、语法结构和结合性不变的特性。

故本题选项A正确。

4.下列运算符中,不能被重载的是( )。

(分数:2.00)A.&&B.!=C..√D.++解析:解析:此题考查的是运算符重载。

在C++中,只有.、*、->*、::、?:这五个运算符不能重载。

5.下列关于运算符重载的描述中,正确的是( )。

c++运算符重载习题

c++运算符重载习题

Task8—1/*1. 定义一个复数类Complex,重载运算符“+",使之能用于复数的加法运算。

将运算符函数重载为非成员、非友元的普通函数.编写程序,求两个复数之和*/#include<iostream>using namespace std;class Complex{public:Complex(){real=0;imag=0;}Complex(double r,double i){real=r;imag=i;}void display();double real;double imag;};void Complex::display(){cout〈<”("〈〈real<<”,”〈<imag<<”i)";}Complex operator +(Complex &c1,Complex &c2){Complex p;p。

real=c1。

real+c2.real;p.imag=c1.imag+c2。

imag;return p;}int main(){Complex c1(3,5),c2(2,5),c3;c1.display();cout〈〈”+";c2。

display();cout〈〈”=”;c3=c1+c2;c3.display();}Task8—2/*2。

定义一个复数类Complex,重载运算符“+”、”-“、”*”、”/”,使之能用于复数的加、减、乘、除。

运算符重载函数作为Complex类的成员函数, 编程,分别求两个复数之和差积商。

*/#include<iostream〉using namespace std;class Complex{public:Complex(){real=0;imag=0;}Complex(double r,double i){real=r;imag=i;}Complex operator+(Complex &c2);Complex operator—(Complex &c2);Complex operator*(Complex &c2);Complex operator/(Complex &c2);void display();private:double real;double imag;};Complex Complex::operator +(Complex &c2){Complex c;c.real=real+c2.real;c。

国家二级C++机试(运算符重载、模板和C++流)模拟试卷6(题后含答案及解析)

国家二级C++机试(运算符重载、模板和C++流)模拟试卷6(题后含答案及解析)

国家二级C++机试(运算符重载、模板和C++流)模拟试卷6(题后含答案及解析)题型有:1. 选择题选择题1.若在表达式y/x中,’’/’’是作为成员函数重载的运算符,则该表达式还可以表示为( )。

A.x.operator/(y)B.operator/(x,y)C.y.operator/(x)D.operator/(y,x)正确答案:C解析:运算符函数的函数名是由运算符前加关键字operator构成的。

所以当“/”作为运算符重载后,其格式为operator/。

所以其作为成员函数调用时的格式为y.operator/(x)。

知识模块:运算符重载2.有类定义如下:class Type{ public:Type(int i=0);Type operator-(int);friend Type operator+(Type,Type);private:int val;};若有对象定义Type c1;则下列语句序列中,错误的是( )。

A.Type(3)+c1;B.e1+Type(3);C.3-c1:D.c1-3;正确答案:C解析:由于在类Type中对“-”进行了重载,所以根据“-”重载的形式定义,c1-3是正确的,而3-c1是错误的表达式。

知识模块:运算符重载3.若要对Data类中重载的加法运算符成员函数进行声明,下列选项中正确的是( )。

A.Data+(Data);B.Data operator+{Data};C.Data+operator{Data};D.operator+(Data,Data);正确答案:B解析:“+”是一个二元运算符,因此作为成员函数重载时参数表中只有一个参数,对应于第二个操作数,而第一个操作数是对象本身。

运算符函数的函数名是由运算符前加关键字operator构成的。

知识模块:运算符重载4.若要对类BigNumber中重载的类型转换运算符long进行声明,下列选项中正确的是( )。

A.operator long( )const;B.operator long(bigNumber);C.long operator long( )const;D.long operator long(BjgNumber);正确答案:A解析:在重载类型转换符时,由于运算符本身已经表示出返回值类型,因此不需要返回值类型的声明。

c运算符的重载习题答案

c运算符的重载习题答案

1.概念填空题1.1运算符重载是对已有的运算符赋予多重含义,使同一个运算符在作用于不同类型对象时导致不同的行为。

运算符重载的实质是函数重载,是类的多态性特征。

1.2可以定义一种特殊的类型转换函数,将类的对象转换成基本数据类型的数据。

但是这种类型转换函数只能定义为一个类的成员函数而不能定义为类的友元函数。

类类型转换函数既没有参数,也不显式给出返回类型。

类类型函数中必须有return 表达式的语句返回函数值。

一个类可以定义多个类类型转换函数。

1.3运算符重载时其函数名由operator运算符构成。

成员函数重载双目运算符时,左操作数是对象,右操作数是函数参数。

2.简答题运算符重载的规则。

2.2简述重载单目运算符++、--,前置和后置时的差别。

2.3 C++中重运算符是否都可以重载?是否都可以重载成类的成员函数?是否都可以重载成类的友元函数?2.4 构造函数作为类型转换函数的条件是什么。

3.选择题3.1在下列运算符中,不能重载的是(B)A.!B. sizeofC. newD. delete3.2 不能用友员函数重载的是(A)。

A.=B.==C.<=D.++3.3下列函数中,不能重载运算符的函数是(B)。

A.成员函数B.构造函数C.普通函数D.友员函数3.4如果表达式++i*k时中的”++”和”*”都是重载的友元运算符,则采用运算符函数调用格式,该表达式还可表示为(B)。

A.operator*(i.operator++(),k) B.operator*(operator++(i),k)C.i.operator++().operator*(k) D.k.operator*(operator++(i))3.5已知在一个类体中包含如下函数原型:VOLUME operator-(VOLUME)const;下列关于这个函数的叙述中,错误的是(B )。

A.这是运算符-的重载运算符函数B.这个函数所重载的运算符是一个一元运算符C.这是一个成员函数D.这个函数不改变数据成员的值3.6在表达式x+y*z中,+是作为成员函数重载的运算符,*是作为非成员函数重载的运算符。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Task8-1/*1.定义一个复数类Complex,重载运算符“+”,使之能用于复数的加法运算。

将运算符函数重载为非成员、非友元的普通函数。

编写程序,求两个复数之和*/#include<iostream>using namespace std;class Complex{public:Complex(){real=0;imag=0;}Complex(double r,double i){real=r;imag=i;}void display();double real;double imag;};void Complex::display(){cout<<"("<<real<<","<<imag<<"i)";}Complex operator +(Complex &c1,Complex &c2){Complex p;p.real=c1.real+c2.real;p.imag=c1.imag+c2.imag;return p;}int main(){Complex c1(3,5),c2(2,5),c3;c1.display();cout<<"+";c2.display();cout<<"=";c3=c1+c2;c3.display();}Task8-2/*2.定义一个复数类Complex,重载运算符“+”、”-“、”*”、”/”,使之能用于复数的加、减、乘、除。

运算符重载函数作为Complex类的成员函数,编程,分别求两个复数之和差积商。

*/#include<iostream>using namespace std;class Complex{public:Complex(){real=0;imag=0;}Complex(double r,double i){real=r;imag=i;}Complex operator+(Complex &c2);Complex operator-(Complex &c2);Complex operator*(Complex &c2);Complex operator/(Complex &c2);void display();private:double real;double imag;};Complex Complex::operator +(Complex &c2){Complex c;c.real=real+c2.real;c.imag=imag+c2.imag;return c;}Complex Complex::operator -(Complex &c2){Complex c;c.real=real-c2.real;c.imag=imag-c2.imag;return c;}Complex Complex::operator *(Complex &c2){Complex c;c.real=real*c2.real;c.imag=imag*c2.imag;return c;}Complex Complex::operator /(Complex &c2){Complex c;c.real=(real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); c.imag=(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); return c;}void Complex::display(){cout<<"("<<real<<","<<imag<<"i)"<<endl;}int main(){Complex c1(3,4),c2(5,-10),c3;c3=c1+c2;cout<<"c1+c2=";c3.display();c3=c1-c2;cout<<"c1-c2=";c3.display();c3=c1*c2;cout<<"c1*c2=";c3.display();c3=c1/c2;cout<<"c1/c2=";c3.display();return 0;}Task8-3/*3.有两个矩阵a和b,均为n行m列(m、n的值自己给出),求两个矩阵之和、差、积、商,重载运算符“+”、”-“、”*”、”/”,使之能用于矩阵向加减乘除,如c=a+b、c=a*b。

*/#include <iostream>#define n 2using namespace std;class Matrix //定义Matrix类{public:Matrix(); //默认构造函数friend Matrix operator+(Matrix &,Matrix &); //重载运算符“+”friend Matrix operator-(Matrix &,Matrix &);friend Matrix operator*(Matrix &,Matrix &);friend Matrix operator/(Matrix &,Matrix &);void input(); //输入数据函数void display(); //输出数据函数private:int mat[n][m];};Matrix::Matrix() //定义构造函数{for(int i=0;i<n;i++)for(int j=0;j<m;j++)mat[i][j]=0;}Matrix operator+(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]+b.mat[i][j];}return c;}Matrix operator-(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]-b.mat[i][j];}return c;}Matrix operator*(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]*b.mat[i][j];}return c;}Matrix operator/(Matrix &a,Matrix &b) //定义重载运算符“+”函数for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]/b.mat[i][j];}return c;}void Matrix::input() //定义输入数据函数{cout<<"input value of matrix:"<<endl;int i,j;for(i=0;i<n;i++){for(j=0;j<m;j++){cin>>mat[i][j];}}}void Matrix::display() //定义输出数据函数{for (int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<mat[i][j]<<" ";}cout<<endl;}}int main(){Matrix a,b,c;a.input();b.input();cout<<endl<<"Matrix a:"<<endl;a.display();cout<<endl<<"Matrix b:"<<endl;b.display();c=a+b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a + Matrix b :"<<endl;c.display();c=a-b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a - Matrix b :"<<endl;c.display();c=a*b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a * Matrix b :"<<endl;c.display();c=a/b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a / Matrix b :"<<endl;c.display();return 0;}Task8-4/*4.在第三题的基础上,重载运算符>>和<<, 使之能用于该矩阵的输入和输出。

*/#include <iostream>#define n 2#define m 3using namespace std;class Matrix //定义Matrix类{public:Matrix(); //默认构造函数friend Matrix operator+(Matrix &,Matrix &); //重载运算符“+”friend Matrix operator-(Matrix &,Matrix &);friend Matrix operator*(Matrix &,Matrix &);friend Matrix operator/(Matrix &,Matrix &);friend ostream& operator<<(ostream& ,Matrix&);friend istream& operator>>(istream& ,Matrix&);void input(); //输入数据函数void display(); //输出数据函数private:int mat[n][m];};Matrix::Matrix() //定义构造函数{for(int i=0;i<n;i++)for(int j=0;j<m;j++)mat[i][j]=0;}Matrix operator+(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]+b.mat[i][j];}return c;}Matrix operator-(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]-b.mat[i][j];}return c;}Matrix operator*(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]*b.mat[i][j];}return c;}Matrix operator/(Matrix &a,Matrix &b) //定义重载运算符“+”函数{Matrix c;for(int i=0;i<n;i++)for(int j=0;j<m;j++){c.mat[i][j]=a.mat[i][j]/b.mat[i][j];}return c;}ostream& operator<<(ostream& out,Matrix& c){for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<c.mat[i][j]<<'\t';cout<<endl;}return out;}istream& operator>>(istream& in,Matrix& c){for(int i=0;i<n;i++){for(int j=0;j<m;j++)cin>>c.mat[i][j];cout<<endl;}return in;}void Matrix::input() //定义输入数据函数{cout<<"input value of matrix:"<<endl;int i,j;for(i=0;i<n;i++){for(j=0;j<m;j++){cin>>mat[i][j];}}}void Matrix::display() //定义输出数据函数{for (int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<mat[i][j]<<" ";}cout<<endl;}}int main(){Matrix a,b,c;cout<<"请输入第一个n*m矩阵"<<endl;cin>>a;cout<<"请输入第二个n*m矩阵"<<endl;cin>>b;cout<<endl<<"Matrix a:"<<endl;cout<<a;cout<<endl<<"Matrix b:"<<endl;cout<<b;c=a+b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a + Matrix b :"<<endl;c=a-b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a - Matrix b :"<<endl;cout<<c;c=a*b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a * Matrix b :"<<endl;cout<<c;c=a/b; //用重载运算符“+”实现两个矩阵相加cout<<endl<<"Matrix c = Matrix a / Matrix b :"<<endl;cout<<c;return 0;}Task8-5/*5.实现分数类中的运算符重载,在分数类中可以完成分数的加减乘除(运算后再化简)、求反、比较(6种关系)的运算。

相关文档
最新文档