#include <iostream>
using namespace std;
/*-------------------------------------------------------------*/
class RMB
{
static int count;
private:
int yuan;
int jiao;
int fen;
public:
//获得当前RMB数量
static int RMBNUM()
{
return count;
}
RMB()
{
count++;
}
RMB(int yuan,int jiao,int fen):yuan(yuan),jiao(jiao),fen(fen)
{
count++;
}
//重载运算符“+”
const RMB operator+(const RMB &other)const
{
RMB temp;
temp.yuan = yuan + other.yuan;
temp.jiao = jiao + other.jiao;
temp.fen = fen + other.fen;
count--;
return temp;
}
//重载运算符“-”
const RMB operator-(const RMB &other)const
{
RMB temp;
temp.yuan = yuan - other.yuan;
temp.jiao = jiao - other.jiao;
temp.fen = fen - other.fen;
count--;
return temp;
}
//判断大小
bool operator>(const RMB &other)
{
int rental,other_rental;
rental = 100*yuan+10*jiao+fen;
other_rental = 100*other.yuan+10*other.jiao+other.fen;
return rental > other_rental;
}
//重载运算符前缀运算“--”
RMB operator--()
{
--yuan;
--fen;
--jiao;
return *this;
}
//重载运算符后缀运算“--”
const RMB operator--(int)
{
RMB temp;
temp.yuan = yuan--;
temp.jiao = jiao--;
temp.fen = fen--;
count--;
return temp;
}
//若有类成员调用析构函数,RMB数量--
void show()
{
cout << "yuan:" << yuan << "\tjiao:" << jiao << "\tfen:" << fen << endl;
}
// ~RMB()
// {
// count--;
// }
};
int RMB::count=0;
int main()
{
RMB RB1(100,5,7);
RMB RB2(100,9,5);
cout << "RB1:";
RB1.show();
cout << "RB2:";
RB2.show();
if(RB1>RB2)
{
cout << "RB1>RB2\n";
}
else
{
cout << "RB1<=RB2\n";
}
cout << "--------------------------------------------------\n";
RMB RB3;
RB3 = RB1+RB2;
cout << "RB3:";
RB3.show();
cout << "------------------------------------------------------\n";
--RB3;
cout << "--RB3:";
RB3.show();
RMB RB4;
RB4=RB3--;
cout <<"RB4(RB3--):";
RB4.show();
cout << "---------------------------------------------------\n";
cout << "count:" << RMB::RMBNUM() << endl;
return 0;
}