分数类的四则运算

/*
* 程序的版权和版本声明部分
* Copyright (c)2014, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称:a.cpp
* 作    者:孔云
* 完成日期:2014年4月21日
* 版 本 号: v1.0
* 输入描述:主函数中给出。
* 问题描述:分数类中的对象可以和整型数进行四则运算,实现分数与整数、分数与分数的比较和四则运算。
* 输出描述:分数与分数、分数与整数的比较结果、加减运算结果。
*/
#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 set(int nu=0,int de=1);
    void display();
    bool operator>(CFraction &);
    bool operator<(CFraction &);
    bool operator>=(CFraction &);
    bool operator<=(CFraction &);
    bool operator==(CFraction &);
    bool operator!=(CFraction &);
    bool operator>(int);
    bool operator<(int);
    bool operator>=(int);
    bool operator<=(int);
    bool operator==(int);
    bool operator!=(int);
    CFraction operator+(int);//加法整数运算
    CFraction operator-(int);//减整数运算
    CFraction friend operator-(int,CFraction &);//减分数运算
    CFraction operator*(int);//乘法运算
    CFraction operator/(int);//除以整数运算
    CFraction friend operator/(int,CFraction &);//整除整数运算
    CFraction operator+(CFraction &t);
    CFraction operator-(CFraction &t);
    CFraction operator*(CFraction &t);
    CFraction operator/(CFraction &t);
    CFraction simplfy(CFraction
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值