这种程序以后还是要自己写,不然能力根本得不到提高!!!我做个示范:
#include<iostream>#include<cstring>
using namespace std;
struct Drink{
string name;
double price;
};
Drink d[6]={{"可乐",3},{"尖叫",3},{"冰峰",15},{"芬达",4},{"雪碧",35},{"脉动",45}};
void print(){
cout<<"=========自动饮料机==========="<<endl;
for(int i=0;i<6;i++){
cout<<(i+1)<<" "<<d[i]name<<"\t"<<d[i]price<<"¥"<<endl;
}
}
int main(){
int tips=0,in,count=0;
char q;
double money,tmp=0;
bool flag=true,f=true;
while(f){
print();
cout<<"请选择饮料类型"<<endl;
cin>>in;
switch(in){
case 1:cout<<d[0]name<<" 价格:"<<d[0]price<<"¥,请投币"<<endl;break;
case 2:cout<<d[1]name<<" 价格:"<<d[1]price<<"¥,请投币"<<endl;break;
case 3:cout<<d[2]name<<" 价格:"<<d[2]price<<"¥,请投币"<<endl;break;
case 4:cout<<d[3]name<<" 价格:"<<d[3]price<<"¥,请投币"<<endl;break;
case 5:cout<<d[4]name<<" 价格:"<<d[4]price<<"¥,请投币"<<endl;break;
case 6:cout<<d[5]name<<" 价格:"<<d[5]price<<"¥,请投币"<<endl;break;
default:cout<<"输入错误,请重新输入"<<endl<<endl;continue;
}
flag=true;
tmp=0;
count=0;
while(flag){
if(count==5){
cout<<"投币错误,请稍后重试"<<endl<<endl;
break;
}
cin>>money;
if(money==100 || money==50 || money==20 || money==10 || money==5 || money==1 || money==05 || money==01){
money+=tmp;
if(money>=d[in-1]price){
cout<<"恭喜您获得一瓶"<<d[in-1]name<<",找零"<<(money-d[in-1]price)<<"¥"<<endl<<endl;
flag=false;
}
else{
tmp=money;
flag=true;
continue;
}
}else{
flag=true;
cout<<"接受面额不符,请重新投入"<<endl;
count++;
continue;
}
cout<<"是否继续购买 Y/N"<<endl;
cin>>q;
if(q=='Y') f=true;
else{
cout<<endl<<"购物结束,欢迎下次光临"<<endl;
f=false;
}
}
}
}
自动售药机 *** 作流程,文末有视频 *** 作版本。
售药机上有二维码,扫码会显示各个系统的药品,选择自己需要的药品,微信付款,药品就出来了。和路边的自动售卖机差不多。
但是为了用药安全,目前只能销售非处方药品。
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
struct Drink{
Drink(float pr, string n);
string name;
float price;
int account;
};
class Vending{
public:
Vending();
inline void showStorage() const {
cout << "可乐:" << m_cola->account << endl << "奶茶:" << m_milkT->account << endl;
cout << "凉茶:" << m_T->account << endl;
}
inline void showSoldNum() const{
cout << m_cola->name << endl << "销售量:" << m_soldCola << endl;
cout << "销售额:" << m_soldCola(m_cola->price) << endl;
cout << m_milkT->name << endl << "销售量:" << m_soldMilkTea << endl;
cout << "销售额:" << m_soldMilkTea(m_milkT->price) << endl;
cout << m_T->name << endl << "销售量:" << m_soldTea << endl;
cout << "销售额:" << m_soldTea(m_T->price) << endl;
}
void addStore();
void sellItem();
void popMenu();
private:
Drink m_cola, m_milkT, m_T;
int m_soldCola, m_soldMilkTea, m_soldTea;
};
Drink::Drink(float pr, string n)
:name(n), price(pr), account(0){}
Vending::Vending()
:m_soldCola(0), m_soldMilkTea(0), m_soldTea(0)
{
m_cola = new Drink(float(28), "可乐");
m_milkT = new Drink(float(30), "奶茶");
m_T = new Drink(float(35), "凉茶");
}
void Vending::addStore(){
cout << "请选择要上架的商品:\n1可乐\n2奶茶\n3凉茶\n";
int n, count;
cin >> n;
if(n > 3){
cout << "选择错误" << endl;
return;
}
cout << "请输入要上架的数量:";
cin >> count;
if(n == 1)
m_cola->account += count;
else if(n == 2)
m_milkT->account += count;
else if(n == 3)
m_T->account += count;
else{
cout << " *** 作失败" << endl;
return;
}
cout << " *** 作完成" << endl;
}
void Vending::sellItem(){
cout << "1" << m_cola->name << ":" << endl;
cout << "价格:" << m_cola->price << ends << "库存:" << m_cola->account << (m_cola->account == 0 "(售完)\n" : "\n");
cout << "2" << m_milkT->name << ":" << endl;
cout << "价格:" << m_milkT->price << ends << "库存:" << m_milkT->account << (m_milkT->account == 0 "(售完)\n" : "\n");
cout << "3" << m_T->name << ":" << endl;
cout << "价格:" << m_T->price << ends << "库存:" << m_T->account << (m_T->account == 0 "(售完)\n" : "\n");
cout << "请选择:";
int n = 0, num = 0;
cin >> n;
float price = 0;
int acc = 0;
if(n == 1){
price = m_cola->price;
acc = m_cola->account;
}
else if(n == 2){
price = m_milkT->price;
acc = m_milkT->account;
}
else if(n == 3){
price = m_T->price;
acc = m_T->account;
}
do
{
if(num > 0)
cout << "库存不足" << endl;
cout << "请输入数量:";
cin >> num;
}while(num > acc);
price = num;
float pay = 0;
do
{
if(pay > 0)
cout << "支付不足" << endl;
cout << "请支付:";
cin >> pay;
}while (pay < price);
cout << " *** 作完成" << endl;
if(pay - price > 0)
cout << "找零:" << pay-price << endl;
if(n == 1){
m_soldCola += num;
m_cola->account -= num;
}
else if(n == 2){
m_soldMilkTea += num;
m_milkT->account -= num;
}
else if(n == 3){
m_soldTea += num;
m_T->account -= num;
}
}
void Vending::popMenu(){
const string menu1 = "========自动贩卖机========\n1管理人员界面\n2销售界面\n3退出\n";
const string menu2 = "========自动贩卖机========\n1显示库存\n2商品上架\n3销售查询\n";
int n;
while(true){
cout << menu1 << "请选择:";
cin >> n;
if(n == 1){
cout << "请输入密码:";
int password;
cin >> password;
if(password != 123){
cout << "密码错误" << endl;
continue;
}
cout << menu2 << "请选择:";
cin >> n;
switch(n){
case 1:{
showStorage();
break;
}
case 2:{
addStore();
break;
}
case 3:{
showSoldNum();
break;
}
default:{
cout << "选择错误" << endl;
return;
}
}
}
else if(n == 2)
sellItem();
else if(n == 3)
exit(0);
}
}
int main(){
Vending vend = new Vending;
vend->popMenu();
return 0;
}
自动售货机被称为24小时营业的微型超市,那么它是如何制造出来的呢?你知道吗?能讲一下制作过程吗?
第一点、制作机身的整体框架。首先工人用钢架焊接出来机身的整体框架,接着再把其他部件安装上去,比如透明的冰柜以及液晶广告屏。然后就是售货机的控制板,将led屏和键盘连接到控制板上,并用螺丝将它们固定。接着是安装投币机或者是现在的收款码,当投入硬币或者扫码支付的时候,金额会被传输到控制版,从而在屏幕上显示。更早的售货机是有找零功能的,随着移动支付的普及,现在基本都取消了。
第二点、组装和安装相应的内部构造。然后是安装上纸钞机,纸钞机和投币机一样,也会将金额传输给控制,并显示在led屏上。接下来是整个售货机的内部安装,首先是塑料托架的组装,工人将隔板安装在底板上,并安上不锈钢塑料托架,同时确保每个仓道的宽度、重量以及形状都不一样,这样会使得售货机在正式面向市场之后可以适应不同的货物商品,能跟好的提供商品服务。
第三点、使用前的测试环节。然后在仓道的后面安装上电动马达,在马达的前面还要安装钢制驱动d簧,这些马达都会连接到控制板,当顾客完成支付后,控制板就会控制相应仓马达旋转驱动d簧并将商品推出,设置好所有的托架后,将商品放入售货机,最后工人要对它进行测试,投入硬币或扫码支付后,看商品是否能被正常推出。测试没问题后,一台自动售货机就这么简单的做好了,对于涉及或者组装不合理的售货机还要再重新返厂维修护理。
以上就是关于c++写自动售货机全部的内容,包括:c++写自动售货机、自动售药机怎么 *** 作、求一个自动贩卖机的C++源代码程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)