#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;
}