c自动售货机源代码 课程设计.docx
《c自动售货机源代码 课程设计.docx》由会员分享,可在线阅读,更多相关《c自动售货机源代码 课程设计.docx(9页珍藏版)》请在冰豆网上搜索。
![c自动售货机源代码 课程设计.docx](https://file1.bdocx.com/fileroot1/2023-2/6/5c84bdd3-5b41-4746-864d-105187aa7cef/5c84bdd3-5b41-4746-864d-105187aa7cef1.gif)
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<"<