• YTU 2633: P3 数钱是件愉快的事


    2633: P3 数钱是件愉快的事

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 387  解决: 215

    题目描述

    超市收银员的钱盒里,各种钞票总是按照面额分类整理,这样做可以提高效率,保证工作质量。
    我们就要制造这个分面额整理钞票的钱盒。为简单起见,只支持百元、拾元和壹元三种纸币。一个钱盒中有4张百元、16张拾元、14张一元钞票,没错,一共574元;另一个钱盒中,12张百元、17张拾元、9张一元钞票,你知道有多少元;将这两个钱盒中的钞票放在同一个盒子里,嘿嘿,这是件愉快的事。
    下面的程序,就完成这件事。不过,设计师写好了类声明,测试员做好了测试函数,钱盒的功能,体现为Money类的构造函数,就等着程序员你来完成了。
    请在begin到end部分写上你该实现的函数,并提交这一部分代码。
    #include<iostream>
    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<<m1<<endl;
        cout<<m2<<endl;
        Money m3;
        m3=m1+m2;
        cout<<m3<<endl;
        return 0;
    }

    输入

    2行,每行3个数字,分别表示2个钱盒中百、拾、壹元钞票的张数

    输出

    输出3行,分别表示前面输入的2个钱盒的情况,以及将2个钱盒相加后的情况
    每个钱盒的输出格式是:
    总面额<-->百元张数*100+拾元张数*10+壹元张数

    样例输入

    4 16 14
    12 17 9

    样例输出

    574<-->4*100+16*10+14
    1379<-->12*100+17*10+9
    1953<-->16*100+33*10+23

    迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

    #include<iostream>
    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);
    };
    Money Money::operator+(const Money &m)
    {
        return Money(hundred+m.hundred,ten+m.ten,one+m.one);
    }
    ostream &operator << (ostream &out,Money m)
    {
        out<<m.hundred*100+m.ten*10+m.one<<"<-->"<<m.hundred<<"*100+"<<m.ten<<"*10+"<<m.one;
        return out;
    }
    Money::Money(int h,int t, int o)
    {
        hundred=h,ten=t,one=o;
    }
    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<<m1<<endl;
        cout<<m2<<endl;
        Money m3;
        m3=m1+m2;
        cout<<m3<<endl;
        return 0;
    }
    

  • 相关阅读:
    html大文件传输技术
    html大文件传输实例解析
    html大文件传输示例
    ckeditor粘贴word图片自动上传功能
    ckeditor不能粘贴word的问题
    ckeditor不能粘贴word的问题如何解决
    vue-ckeditor-word粘贴
    vue中使用ckeditor,支持wps,word,网页粘贴
    富文本编辑器复制word
    富文本编辑器粘贴word
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989511.html
Copyright © 2020-2023  润新知