【任务3】接第8周任务3,定义分数类中<<和>>运算符重载,实现分数的输入输出,改造原程序中对运算结果显示方式,使程序读起来更自然。
#include <iostream>
using namespace std;
class CFraction
{
private:
int nume; // 分子
int deno; // 分母
public:
CFraction(int nu=0,int de=1):nume(nu),deno(de){}
void simplify();
friend istream& operator >> (istream& input, CFraction& c);
friend ostream& operator << (ostream& output, CFraction& c);
int gcd(int x,int y);
CFraction operator+(const CFraction &c); //两个分数相加,结果要化简
CFraction operator-(const CFraction &c); //两个分数相减,结果要化简
CFraction operator*(const CFraction &c); //两个分数相乘,结果要化简
CFraction operator/(const CFraction &c); //两个分数相除,结果要化简
CFraction operator+(); //取正一目运算
CFraction