这个参考答案好像有问题
这是我参照上一个写的答案
#include <stdio.h>
class Dollar {
public:
Dollar operator + (const Dollar & doll);
Dollar(int _yuan,int _fen);
~Dollar();
int yuan = 0;
int fen = 0;
};
Dollar ::Dollar(int _yuan,int _fen){
yuan =_yuan;
fen= _fen;
}
Dollar::~Dollar()
{
}
Dollar Dollar::operator + (const Dollar & doll)
{
Dollar dollarRes(0,0);
int c = doll.fen + fen;
dollarRes.fen = c % 100;
int d = doll.yuan + yuan;
dollarRes.yuan = d + c / 100;
return dollarRes;
}
int main(int argc,char **argv)
{
Dollar dollarA(4, 9);
Dollar dollarB(1, 3);
Dollar dollarC = dollarA + dollarB;
printf("%d.%d",dollarC.yuan,dollarC.fen);
return 0;
}