returntrue;
}
returnfalse;
}
fraction&operator=(constfraction&other){
num=other.num;
den=other.den;
return*this;
}
fractionoperator+(constfraction&other){
fractionres;
res.num=num*other.den+den*other.num;
res.den=den*other.den;
returnres;
}
fractionoperator-(constfraction&other){
fractionres;
res.num=num*other.den-den*other.num;
res.den=den*other.den;
returnres;
}
fractionoperator*(constfraction&other){
returnfraction(num*other.num,den*other.den);
}
fractionoperator/(constfraction&other){
returnfraction(num*other.den,den*other.num);
}
voiddisplay()
{
cout<}
private:
intnum,den;
};
voidmain()
{
fractiona(2,5);
fractionb(a);
fractionc;
b=fraction(3,7);
c=a+b;
c.display();
c=a-b;
c.display();
c=a*b;
c.display();
c=a/b;
c.display();
}
结果: