欢迎来到天天文库
浏览记录
ID:52563654
大小:36.00 KB
页数:6页
时间:2020-03-28
《C++自动售货机源代码-课程设计.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#includeusingnamespacestd;classmoneycounter{public:moneycounter()//初始化{input_money=0.0;}~moneycounter(){}voidgetmoney();提示顾客投币floatmoney_from_buyer();投币金额voidclear();//清空,准备下一轮投币private:floatinput_money;//顾客投入的金额};classgoodsinfo{public:goo
2、dsinfo(){name="";price=0.0;total=0;}~goodsinfo(){}voidset_goods(string,float,int);stringgoods_name();floatgoods_price();intgoods_number();private:stringname;floatprice;inttotal;};classdrinkmachine{public:drinkmachine();~drinkmachine(){}voidshowchoices();//显示饮料信息voidinputmoney();获取顾客
3、投入的钱币boolgoodsitem(int);//检查饮料的状态voidreturn_allmoney();返回钱数voidreturn_money();voiddeal_money(intselect);private:moneycountermoneyctr;goodsinfov_goods[5];};staticfloatchange;voidmoneycounter::getmoney(){floatmoney;cout<>money;input_money+=money;change=input_
4、money;cout<5、;}stringgoodsinfo::goods_name(){returnname;}floatgoodsinfo::goods_price(){returnprice;}intgoodsinfo::goods_number(){returntotal;}//*******************************************drinkmachine::drinkmachine(){v_goods[0].set_goods("橙汁",3,20);v_goods[1].set_goods("咖啡",5,0);v_goods[2].set_go6、ods("纯净水",1.5,20);v_goods[3].set_goods("可口可乐",2,30);v_goods[4].set_goods("百事可乐",2,28);}voiddrinkmachine::showchoices(){cout<7、ne::inputmoney(){cout<0){if(moneyctr.money_from_buyer()>=v_goods[select].goods_price()){floatchange=moneyctr.money_from_buyer()8、-v_goods[select].go
5、;}stringgoodsinfo::goods_name(){returnname;}floatgoodsinfo::goods_price(){returnprice;}intgoodsinfo::goods_number(){returntotal;}//*******************************************drinkmachine::drinkmachine(){v_goods[0].set_goods("橙汁",3,20);v_goods[1].set_goods("咖啡",5,0);v_goods[2].set_go
6、ods("纯净水",1.5,20);v_goods[3].set_goods("可口可乐",2,30);v_goods[4].set_goods("百事可乐",2,28);}voiddrinkmachine::showchoices(){cout<7、ne::inputmoney(){cout<0){if(moneyctr.money_from_buyer()>=v_goods[select].goods_price()){floatchange=moneyctr.money_from_buyer()8、-v_goods[select].go
7、ne::inputmoney(){cout<0){if(moneyctr.money_from_buyer()>=v_goods[select].goods_price()){floatchange=moneyctr.money_from_buyer()
8、-v_goods[select].go
此文档下载收益归作者所有