#include <iostream>
using namespace std;
class CFraction
{
private:
int nume; // 分子
int deno; // 分母
public:
CFraction(int n=0,int d=1):nume(n),deno(d){};
CFraction operator +(CFraction &a);
CFraction operator -(CFraction &a);
CFraction operator +(int a);
CFraction operator -(int a);
void display();
//构造函数及运算符重载的函数声明
};
void CFraction::display()
{
cout<<nume<<"/"<<deno;
}
CFraction CFraction::operator +(int a)
{
CFraction b;
b.nume=nume+a*deno;
b.deno=deno;
return b;
}
CFraction CFraction::operator -(int a)
{
CFraction b;
b.nume=nume-a*deno;
b.deno=deno;
return b;
}
CFraction CFraction::operator -(CFraction &a)
{
CFraction b;
b.nume=nume*a.deno-a.nume*deno;
b.deno=deno*a.deno;
return b;
}
CFraction CFraction::operator +(CFraction &a)
{
CFraction b;
b.nume=nume*a.deno+a.nume*deno;
b.deno=deno*a.deno;
return b;
}
//重载函数的实现及用于测试的main()函数
int main()
{
CFraction a(5,6),d(1,2),c;
c=a+d;
c.display();
return 0;
}