OJ第三批——Problem R:P3 数钱是件愉快的事

问题及代码:

Problem R: P3 数钱是件愉快的事

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 356   Solved: 189
[ Submit][ Status][ Web Board]

Description

超市收银员的钱盒里,各种钞票总是按照面额分类整理,这样做可以提高效率,保证工作质量。
我们就要制造这个分面额整理钞票的钱盒。为简单起见,只支持百元、拾元和壹元三种纸币。一个钱盒中有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;
}

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

HINT

 

#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 *****************
Money ::Money(int h,int t,int o)
{
    hundred=h;
    ten=t;
    one=o;
}

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;
}
//************* 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;
}


 

运行结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值