⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 自动售货机.cpp

📁 VC各工程的源码集合
💻 CPP
字号:
#include<iostream.h>
#include"zidongshouhuoji.h"
void showselection();
void sellproduct(shouhuoji &p,shouyinji &m);

void main()
{
	shouyinji syj(800);
	shouhuoji tangguo(100,2);
	shouhuoji binggan(100,3);
	int choice;  
	showselection();
	cin>>choice;
	while(choice!=9)
	{
		switch(choice)
		{
		case 1:
			cout<<"糖果还有"<<tangguo.amount()<<"包"<<endl;
			sellproduct(tangguo,syj);					
			break;
		case 2:
			cout<<"饼干还有"<<binggan.amount()<<"包"<<endl;
			sellproduct(binggan,syj);
			break;
		default:
			cout<<"您输入有误!"<<endl;
			cout<<"*************************************************";
	        cout<<"*******************************";
		}
	showselection();
	cin>>choice;
	}
}

void sellproduct(shouhuoji &p,shouyinji &m)
{
	int money,add;
	if(p.amount()>0)
	{
		cout<<"请投入"<<p.price()<<"元:";
		cin>>money;
		if(money<p.price())
		{
			cout<<"您投入的钱不够,"
				<<"请再投入"
				<<p.price()-money<<"元:";
			cin>>add;
			money=money+add;
		}
		if(money>=p.price())
		{
			m.acceptAmount(money);
			p.makesale();
		}
		cout<<"请从底部取走,谢谢光临!"<<endl;
		cout<<"收银机里有金额:"<<m.cashNow()<<"元"<<endl;
	}
	else
		cout<<"对不起,该商品已售完!"<<endl;
	    cout<<"*************************************************";
	    cout<<"*******************************";
}
void showselection()
{
	cout<<"                        "
		<<"您好,欢迎光临自动售货机!"<<endl;
	cout<<"*************************************************";
	cout<<"*******************************";
	cout<<"1是糖果, "<<"2是饼干, "<<"9退出"<<endl
		<<"请选择:";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -