#include <iostream>
using namespace std;
class RMB
{
private:
int Y;//元
int J;//角
int F;//分
static int count;//成员个数
public:
//无参构造函数
RMB()
{
count++;
}
//有参构造函数
RMB(int Y,int J,int F):Y(Y),J(J),F(F)
{
count++;
}
void show()
{
if(F >= 10)
{
J += F / 10;
F %= 10;
}
if(J >= 10)
{
Y += J / 10;
J %= 10;
}
double rmb = Y + J/10.0 + F/100.0;
cout << "RMB:" << rmb << "元" << endl;
}
//析构函数
~RMB()
{
count--;
}
//获取count
static int getcount()
{
return count;
}
//成员函数实现+号运算符重载
const RMB operator+(const RMB &R) const
{
RMB temp;
temp.Y = Y + R.Y;
temp.J = J + R.J;
temp.F = F + R.F;
return temp;
}
//成员函数实现-号运算符重载
const RMB operator-(const RMB &R) const
{
RMB temp;
temp.Y = Y - R.Y;
temp.J = J - R.J;
temp.F = F - R.F;
return temp;
}
//成员函数实现>号运算符重载
bool operator>(const RMB &R) const
{
if((Y+J/10.0+F/100.0)>(R.Y+R.J/10.0+R.F/100.0))
return true;
else
return false;
}
//成员函数实现前--运算符重载
RMB &operator--()
{
--Y;
--J;
--F;
return *this;
}
//成员函数实现后--运算符重载
const RMB operator--(int)
{
RMB temp;
temp.Y = Y--;
temp.J = J--;
temp.F = F--;
return temp;
}
};
int RMB::count = 0;
int main()
{
RMB a(20,20,20);
RMB b(5,5,5);
RMB c = a + b;
c--;
c.show();
RMB d = a - b;
--d;
d.show();
RMB *p = new RMB;
if(c>d)
{
cout << "c>d" << endl;
}
cout << "目前已创建RMB对象的数量:" << RMB::getcount() << endl;
delete p;
cout << "目前已创建RMB对象的数量:" << RMB::getcount() << endl;
return 0;
}