端午节啊啊啊啊

#include <iostream>
 
using namespace std;
class RMB{
private:
    int yuan;
    int jiao;
    int fen;
    static int count;
public:
    RMB(){cout << "RMB::无参初始化完成" << endl;
         count++;}
    RMB(int yuan,int jiao,int fen):yuan(yuan),jiao(jiao),fen(fen){
        cout << "RMB::有参初始换完成" << endl;
        count++;
    }
    ~RMB(){
        count--;
        cout <<"RMB对象以销毁" << endl;
    }
    RMB(const RMB &other) : yuan(other.yuan), jiao(other.jiao), fen(other.fen) {
        cout << "RMB::拷贝构造函数完成" << endl;
        count++;
    }
    const RMB operator+( RMB &R)const{
        RMB temp;
        temp.yuan=yuan+R.yuan;
        temp.jiao=jiao+R.jiao;
        temp.fen=fen+R.fen;
        if(temp.fen/10>0){
            temp.jiao+=(temp.fen/10);
            temp.fen-=10;
        }
        if(temp.jiao/10>0){
            temp.yuan+=(temp.jiao/10);
            temp.jiao-=10;
        }
        return temp;
    }
    const RMB operator-(const RMB &R)const{
        RMB temp;
        temp.yuan=yuan-R.yuan;
        temp.jiao=jiao-R.jiao;
        temp.fen=fen-R.fen;
        if(temp.fen/10<0){
            temp.jiao-=1;
            temp.fen+=10;
        }
        if(temp.jiao/10<0){
            temp.yuan-=1;
            temp.jiao+=10;
        }
        return temp;
    }
    bool operator>(const RMB &R){
        if(yuan>R.yuan){
            return true;
        }else if(jiao>R.jiao){
            return true;
        }else if(fen>R.fen){
            return true;
        }else{
            return false;
        }
    }
    RMB &operator--(){
        --yuan;
        --jiao;
        --fen;
        if(jiao<0){
            yuan--;
            jiao+=10;
        }
        if(fen<0){
            jiao--;
            fen+=10;
        }
        return *this;
    }
    const RMB operator--(int){
        RMB temp;
        temp.yuan=yuan--;
        temp.jiao=jiao--;
        temp.fen=fen--;
        if(temp.jiao<0){
            temp.yuan--;
            temp.jiao+=10;
        }
        if(temp.fen<0){
           temp.jiao--;
            temp.fen+=10;
        }
        return temp;
    }
    void display(){
        cout <<"yuan=" << yuan << "jiao=" << jiao << "fen=" << fen <<endl;
    }
    static void RMB_num(){
        cout << "当前RMB类有" << count << "个"<< endl;
    }
};
int RMB::count=0;
int main()
{
    RMB r1(10,5,6);
    RMB r2(10,5,6);
    RMB r3=r1+r2;
    r3.display();
    cout << "________________" <<endl;
    if(r3>r2){
        cout << "r3>r2" << endl;
    }else{
        cout << "r2>r3" << endl;
    }
    cout << "_______________" <<endl;
    RMB r4=r3--;
    r4.display();
    cout <<"________________" << endl;
    RMB r5=--r3;
    r5.display();
    cout <<"________________" <<endl;
    r5.RMB_num();
 
 
    return 0;
}

 

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值