一、程序名称:自动售货机二、程序功能:将程序中的数组输出,并分别按从大到小和从小到大的顺序输出,在输出4.4三、程序设计及实现。1、主函数:main()实现程序的主界面2、public公有成员、private私有成员3、数据设置为string字符串类型、float单精度类型、int整形4、输出:cout用来输出显示的内容5、选择语句:switch()case1:6、实现简单的界面设计,类的成员变量,调用函数,循环,if语句可操作销售、支付、上架、找零等功能四、程序运行结果:五、程序代码//头文件#includeiostream#includestring#includevector#includecstdlibusingnamespacestd;//命名空间structDrink{Drink(floatpr,stringn);stringname;//字符串类型floatprice;//单精度intaccount;//整形};classVending{public:Vending();//类的公有成员inlinevoidshowStorage()const{cout可乐:m_cola-accountendl奶茶:m_milkT-accountendl;cout凉茶:m_T-accountendl;}inlinevoidshowSoldNum()const{coutm_cola-nameendl销售量:m_soldColaendl;cout销售额:m_soldCola*(m_cola-price)endl;coutm_milkT-nameendl销售量:m_soldMilkTeaendl;cout销售额:m_soldMilkTea*(m_milkT-price)endl;coutm_T-nameendl销售量:m_soldTeaendl;cout销售额:m_soldTea*(m_T-price)endl;}voidaddStore();voidsellItem();voidpopMenu();private://类的私有成员Drink*m_cola,*m_milkT,*m_T;intm_soldCola,m_soldMilkTea,m_soldTea;};Drink::Drink(floatpr,stringn):name(n),price(pr),account(10){}//名称、价格、库存数量//销售界面Vending::Vending():m_soldCola(0),m_soldMilkTea(0),m_soldTea(0){m_cola=newDrink(float(2.8),可乐);m_milkT=newDrink(float(3.0),奶茶);m_T=newDrink(float(3.5),凉茶);}//上架界面voidVending::addStore(){cout请选择要上架的商品:\n1.可乐\n2.奶茶\n3.凉茶\n;intn,count;cinn;if(n3){cout选择错误endl;return;}cout请输入要上架的数量:;cincount;if(n==1)m_cola-account+=count;elseif(n==2)m_milkT-account+=count;elseif(n==3)m_T-account+=count;else{cout操作失败endl;return;}cout操作完成endl;}//销售界面voidVending::sellItem(){cout1.m_cola-name:endl;cout价格:m_cola-priceends库存:m_cola-account(m_cola-account==0?(售完)\n:\n);cout2.m_milkT-name:endl;cout价格:m_milkT-priceends库存:m_milkT-account(m_milkT-account==0?(售完)\n:\n);cout3.m_T-name:endl;cout价格:m_T-priceends库存:m_T-account(m_T-account==0?(售完)\n:\n);cout请选择:;intn=0,num=0;cinn;floatprice=0;intacc=0;if(n==1){price=m_cola-price;acc=m_cola-account;}elseif(n==2){price=m_milkT-price;acc=m_milkT-account;}elseif(n==3){price=m_T-price;acc=m_T-account;}do{if(num0)cout库存不足endl;cout请输入数量:;cinnum;}while(numacc);price*=num;//支付floatpay=0;do{if(pay0)cout支付不足endl;cout请支付:;cinpay;}while(payprice);cout操作完成endl;if(pay-price0)cout找零:pay-priceendl;if(n==1){m_soldCola+=num;m_cola-account-=num;}elseif(n==2){m_soldMilkTea+=num;m_milkT-account-=num;}elseif(n==3){m_soldTea+=num;m_T-account-=num;}}voidVending::popMenu(){conststringmenu1=========自动贩卖机========\n1.管理人员界面\n2.销售界面\n3.退出\n;conststringmenu2=========自动贩卖机========\n1.显示库存\n2.商品上架\n3.销售查询\n;intn;while(true){coutmenu1请选择:;cinn;if(n==1){cout请输入密码:;intpassword;cinpassword;if(password!=123){//密码为123,输入不是123则现实密码错误cout密码错误endl;continue;}coutmenu2请选择:;cinn;switch(n){//选择语句case1:{showStorage();break;}case2:{addStore();break;}case3:{showSoldNum();break;}default:{cout选择错误endl;return;}}}elseif(n==2)sellItem();elseif(n==3)exit(0);}}//main()函数的实现,程序的主界面的引导intmain(){Vending*vend=newVending;vend-popMenu();return0;}