OJ期末模考G

2019-04-14 12:46发布

Problem G: P3 数钱是件愉快的事 Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 339  Solved: 176
[Submit][Status][Web Board]
Description 超市收银员的钱盒里,各种钞票总是按照面额分类整理,这样做可以提高效率,保证工作质量。 我们就要制造这个分面额整理钞票的钱盒。为简单起见,只支持百元、拾元和壹元三种纸币。一个钱盒中有4张百元、16张拾元、14张一元钞票,没错,一共574元;另一个钱盒中,12张百元、17张拾元、9张一元钞票,你知道有多少元;将这两个钱盒中的钞票放在同一个盒子里,嘿嘿,这是件愉快的事。 下面的程序,就完成这件事。不过,设计师写好了类声明,测试员做好了测试函数,钱盒的功能,体现为Money类的构造函数,就等着程序员你来完成了。 请在beginend部分写上你该实现的函数,并提交这一部分代码。 #include using namespace std; class Money { private:     int hundred;   //百元张数     int ten;       //拾百元张数     int one;       //壹元张数 public:     Money(int h=0,int t=0, int o=0);     Money operator+(const Money &m);     friend ostream &operator<<(ostream &out,Money m); }; //************* begin ***************** //************* end ***************** int main() {     int mh1, mt1, mo1, mh2, mt2,mo2;     cin>>mh1>>mt1>>mo1;     cin>>mh2>>mt2>>mo2;     Money m1(mh1, mt1, mo1), m2(mh2, mt2,mo2);     cout<     cout<     Money m3;     m3=m1+m2;     cout<     return 0; } Input 2行,每行3个数字,分别表示2个钱盒中百、拾、壹元钞票的张数 Output 输出3行,分别表示前面输入的2个钱盒的情况,以及将2个钱盒相加后的情况 每个钱盒的输出格式是: 总面额<-->百元张数*100+拾元张数*10+壹元张数 Sample Input 4 16 14 12 17 9 Sample Output 574<-->4*100+16*10+14 1379<-->12*100+17*10+9 1953<-->16*100+33*10+23   Submit: #include using namespace std; class Money { private: int hundred; //百元张数 int ten; //拾百元张数 int one; //壹元张数 public: Money(int h=0,int t=0, int o=0); Money operator+(const Money &m); friend ostream &operator<<(ostream &out,Money m); }; //************* begin ***************** Money::Money(int h,int t,int o){hundred=h;ten=t;one=o;} Money Money::operator+(const Money &m) { Money M; M.hundred=hundred+m.hundred; M.ten=ten+m.ten; M.one=one+m.one; return M; } ostream &operator<<(ostream &out,Money m) { out<"<>mh1>>mt1>>mo1; cin>>mh2>>mt2>>mo2; Money m1(mh1, mt1, mo1), m2(mh2, mt2,mo2); cout<
 

热门文章