c自动售货机源代码 课程设计.docx

上传人:b****7 文档编号:9765805 上传时间:2023-02-06 格式:DOCX 页数:9 大小:15.30KB
下载 相关 举报
c自动售货机源代码 课程设计.docx_第1页
第1页 / 共9页
c自动售货机源代码 课程设计.docx_第2页
第2页 / 共9页
c自动售货机源代码 课程设计.docx_第3页
第3页 / 共9页
c自动售货机源代码 课程设计.docx_第4页
第4页 / 共9页
c自动售货机源代码 课程设计.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

c自动售货机源代码 课程设计.docx

《c自动售货机源代码 课程设计.docx》由会员分享,可在线阅读,更多相关《c自动售货机源代码 课程设计.docx(9页珍藏版)》请在冰豆网上搜索。

c自动售货机源代码 课程设计.docx

c自动售货机源代码课程设计

{

public:

moneycounter()//初始化

{

input_money=0.0;

}

~moneycounter(){}

voidgetmoney();提示顾客投币

floatmoney_from_buyer();投币金额

voidclear();//清空,准备下一轮投币

private:

floatinput_money;//顾客投入的金额

};

classgoodsinfo

{

public:

goodsinfo()

{

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();获取顾客投入的钱币

boolgoodsitem(int);//检查饮料的状态

voidreturn_allmoney();返回钱数

voidreturn_money();

voiddeal_money(intselect);

private:

moneycountermoneyctr;

goodsinfov_goods[5];

};

staticfloatchange;

voidmoneycounter:

:

getmoney()

{

floatmoney;

cout<

"<

cin>>money;

input_money+=money;

change=input_money;

cout<

"<

}

floatmoneycounter:

:

money_from_buyer()

{

returninput_money;

}

voidmoneycounter:

:

clear()

{

input_money=0.0;

}

//*******************************************************

voidgoodsinfo:

:

set_goods(stringn,floatp,intnum)

{

name=n;

price=p;

total=num;

}

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_goods("纯净水",1.5,20);

v_goods[3].set_goods("可口可乐",2,30);

v_goods[4].set_goods("百事可乐",2,28);

}

voiddrinkmachine:

:

showchoices()

{

cout<

for(inti=0;i<5;i++)

{

cout<

}

cout<<"5退款并且退出"<

}

voiddrinkmachine:

:

inputmoney()

{

cout<

"<

}

booldrinkmachine:

:

goodsitem(intselect)

{

intnumber=v_goods[select].goods_number();

if(number>0)

{

if(moneyctr.money_from_buyer()>=v_goods[select].goods_price())

{

floatchange=moneyctr.money_from_buyer()-v_goods[select].goods_price();

returntrue;

}

else

{

cout<

"<

returnfalse;

}

}

else

{

cout<

"<

returnfalse;

}

returnfalse;

}

voiddrinkmachine:

:

deal_money(intselect)

{

change-=v_goods[select].goods_price();

if(change<0)

{

cout<<"您的余额不足!

";

change+=v_goods[select].goods_price();

}

}

voiddrinkmachine:

:

return_allmoney()

{

cout<

"<

return;

}

voiddrinkmachine:

:

return_money()

{

cout<

"<

}

voidmain()

{

drinkmachinedri;

stringbuf;

boolgo_on(true),cash_on(true),got_it(true);

booljudge=true;

intcount=0;

cout<

====================="<

while(go_on)

{

while(cash_on&&judge)

{

dri.inputmoney();

cout<

(y/n)";动售货机cin>>buf;

if(buf=="n")

{

cash_on=false;

break;

}

}

dri.showchoices();

cin>>buf;

intselect=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);

}

cout<

(y/n)";

cin>>buf;

if(buf=="y")

{

cash_on=true;

go_on=true;

}

else

{

got_it=dri.goodsitem(select);

dri.return_money();

cout<

"<

go_on=false;

}

}

}

}cout<

"<

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1