已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include #includeusing namespace std;class moneycounterpublic:moneycounter()/初始化input_money=0.0;moneycounter() void getmoney();提示顾客投币 float money_from_buyer();投币金额 void clear();/清空,准备下一轮投币 private:float input_money;/顾客投入的金额;class goodsinfopublic:goodsinfo()name=;price=0.0;total=0;goodsinfo() void set_goods(string,float,int); string goods_name(); float goods_price(); int goods_number();private:string name; float price; int total;class drinkmachinepublic:drinkmachine(); drinkmachine() void showchoices();/显示饮料信息 void inputmoney();获取顾客投入的钱币 bool goodsitem(int);/检查饮料的状态 void return_allmoney();返回钱数void return_money();void deal_money(int select);private:moneycounter moneyctr; goodsinfo v_goods5;static float change;void moneycounter:getmoney()float money; coutendl请投入钱币。money; input_money += money;change = input_money; coutendl您投入的金额是input_money元。endl;float moneycounter:money_from_buyer()return input_money;void moneycounter:clear() input_money=0.0;/*void goodsinfo:set_goods(string n,float p,int num) name=n; price=p; total=num;string goodsinfo:goods_name() return name;float goodsinfo:goods_price() return price;int goodsinfo:goods_number() return total;/*drinkmachine:drinkmachine() v_goods0.set_goods(橙汁,3,20); v_goods1.set_goods(咖啡,5,0); v_goods2.set_goods(纯净水,1.5,20); v_goods3.set_goods(可口可乐,2,30); v_goods4.set_goods(百事可乐,2,28);void drinkmachine:showchoices()coutendl请选择商品代码endl; for(int i=0;i5;i+) couti v_goodsi.goods_name() v_goodsi.goods_price()元endl; cout5 退款并且退出endl;void drinkmachine:inputmoney() coutendl本机只接受10元、5元、2元、1元和0.5元的纸币和硬币。0) if(moneyctr.money_from_buyer()=v_goodsselect.goods_price() float change=moneyctr.money_from_buyer()-v_goodsselect.goods_price(); return true; elsecoutendl您投入的金额不足!endl;return false; else coutendl您选择的饮料已售完!endl;return false; return false;void drinkmachine:deal_money(int select)change -= v_goodsselect.goods_price();if(change 0)cout您的余额不足!;change += v_goodsselect.goods_price();void drinkmachine:return_allmoney()coutendl退款moneyctr.money_from_buyer()元。endl;return;void drinkmachine:return_money() coutendl找零change元。endl;void main() drinkmachine dri; string buf; bool go_on(true),cash_on(true),got_it(true); bool judge = true; int count = 0; coutendl=欢迎使用本自动售货机=endlendl; while(go_on) while(cash_on & judge) dri.inputmoney(); coutendlbuf; if(buf=n) cash_on=false; break; dri.showchoices(); cinbuf; int select=atoi(buf.c_str(); if(select=5) if(count = 0) dri.return_allmoney(); else dri.return_money(); go_on = false; else got_it=dri.goodsitem(select); judge = false; if(got_it) dri.deal_money(select); coutendlbuf; if(buf=y) cash_on=t
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高中生物2026教资面试答辩试卷及解析
- 2026高中语文教资面试历年真题试卷及解析
- 小学数学2026教资面试试讲经典考题试卷及答案
- 初中英语2026教资面试结构化问答全真模拟题库及答案
- 护理排痰操作流程图解
- 肝性脑病昏迷的护理
- 房地产路演课件
- 房地产地税课件
- 风电安全课件
- 房产运营课件
- T∕CCEAS008-2026 建设工程造价咨询成果文件质量标准
- 水利安全风险防控“六项机制”与安全生产培训
- QGDW12505-2025电化学储能电站安全风险评估规范
- 亚通电子新材料(湖州)有限公司先进连接材料智能制造产业化基地及技术创新中心建设项目报告
- 航空服务礼仪与沟通技巧题库
- (一模)贵阳市2025年高三年级适应性考试(一)物理试卷(含答案)
- 《健康档案管理》课件
- 顶管工程施工顶进力估算、后背墙设计计算
- DL-T626-2015劣化悬式绝缘子检测规程
- 华住会酒店员工手册
- 青岛版九年级数学上册 (一元二次方程根的判别式)教育教学课件
评论
0/150
提交评论