#include <iostream>
using namespace std;
class RMB
{
int yuan;
int jiao;
int fen;
static int count;
public:
RMB(){
count++;
}
RMB(int yuan,int jiao,int fen):yuan(yuan),jiao(jiao),fen(fen){
count++;
}
//加法
const RMB operator+(const RMB &r)
{
RMB temp;
int a=0,b=0;
temp.fen=this->fen+r.fen;
if(temp.fen>10)
{
temp.fen=temp.fen%10;
a++;
}
if(a==1)
{
temp.jiao=this->jiao+r.jiao+1;
a--;
}else
{
temp.jiao=this->jiao+r.jiao;
}
if(temp.jiao>10)
{
temp.jiao=temp.jiao%10;
b++;
}
if(b==1)
{
temp.yuan=this->yuan+r.yuan+1;
b--;
}else
{
temp.yuan=this->yuan+r.yuan;
}
return temp;
}
//减法
const RMB operator-(const RMB &r)
{
RMB temp;
int a=0,b=0;
if(yuan<r.yuan)
{
cout << "账户余额不足" << endl;
}else
{
//分减法
if(fen<r.fen)
{
a++;
temp.fen=fen+10-r.fen;
}else
{
temp.fen=fen-r.fen;
}
//角减法
if(jiao<r.jiao)
{
if(a==1)
{
temp.jiao=10+jiao-1-r.jiao;
a--;
b++;
}else
{
temp.jiao=10+jiao-r.jiao;
b++;
}
}else
{
if(a==1)
{
temp.jiao=jiao-1-r.jiao;
a--;
b++;
}else
{
temp.jiao=jiao-r.jiao;
b++;
}
}
//元减法
if(b==1)
{
temp.yuan=yuan-1-r.yuan;
b--;
}else
{
temp.yuan=yuan-r.yuan;
}
}
return temp;
}
//大于
bool operator>(const RMB &r) const
{
if(yuan>r.yuan)
{
return true;
}else if(yuan==r.yuan)
{
if(jiao>r.jiao)
{
return true;
}else if(jiao==r.jiao)
{
if(fen>r.fen)
{
return true;
}else if(fen==r.fen)
{
cout << "余额相同" << endl;
}else
{
return false;
}
}else
{
return false;
}
}else
{
return false;
}
}
//
RMB &operator--()
{
--yuan;
--jiao;
--fen;
return *this;
}
~RMB()
{
count--;
}
void show()
{
cout << yuan << " " << jiao << " " << fen << endl;
cout << "目前有" << count << "个账户在线" << endl;
}
};
int RMB::count=0;
int main()
{
RMB r1(14,9,6);
RMB r2(15,5,3);
RMB r3=r1+r2;
r3.show();
--r3;
r3.show();
return 0;
}