OJ期末模考G
2015-06-28 14:57
162 查看
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类的构造函数,就等着程序员你来完成了。
请在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
Submit:
数钱是件愉快的事
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类的构造函数,就等着程序员你来完成了。
请在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
Submit:
#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) { 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<<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; }
相关文章推荐
- Kruskal-Wallis Test and Friedman test
- 动态规划问题 字符串相似度 和字符串最长公共子序列
- hdu 3348
- 类目、延展、协议
- OJ期末模考F
- Linux进程间通信--进程,信号,管道,消息队列,信号量,共享内存
- (转) 经典SQL练习题
- wilcoxon test
- 使用c语言访问mysql数据库
- AT&T Assembly Language Note
- codeforces 556B. Case of Fake Numbers 解题报告
- python实现将html表格转换成CSV文件的方法
- Jqgrid+Struts2实现的增删改查(一)
- JS删除数组中重复的数据
- OJ期末模考E
- 阻止事件冒泡
- Effective Objective-C 2.0之Note.03(属性详解)
- hdu -2222 Keywords Search(AC自动机模板)
- CSAPP的笔记与心得
- OJ期末模考D