#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(2.8), "可乐")
m_milkT = new Drink(float(3.0), "奶茶")
m_T = new Drink(float(3.5), "凉茶")
}
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
}
#include "iostream"#include "string"
using namespace std
class MoneyCounter
{
private:
float input_money
public:
void getmoney()
float money_from_buyer()
void return_money(float change)
void clear()
MoneyCounter()
~ MoneyCounter()
}
class GoodsInfo
{
private:
string name
float price
int total
public:
GoodsInfo()
~GoodsInfo()
void set_goods(string n,float p,int t)
string goods_name()
float goods_price()
int goods_total()
void goods_disp()
}
class DrinkMachine
{
private:
MoneyCounter moneyctr
GoodsInfo v_goods[5]
public:
DrinkMachine()
~DrinkMachine()
void showMenu()
void inputmoney()
bool goodsitem(int)
void return_allmoney()
}
MoneyCounter::MoneyCounter()
{
input_money=0.0f
}
MoneyCounter::~MoneyCounter()
{
}
void MoneyCounter::getmoney()
{
float money
cout<<"一组温馨提示<*_*>->请投入钱币"<<endl
cin>>money
input_money=input_money+money
cout<<"你投入的金额是 一组温馨提示<*_*>:"<<input_money<<endl
}
float MoneyCounter::money_from_buyer()
{
return input_money
}
void MoneyCounter::clear()
{
input_money=0.0f
}
void MoneyCounter::return_money(float change)
{
cout<<"一组温馨提示<*_*>\n找零"<<change<<"元"<<endl
}
GoodsInfo::GoodsInfo()
{
name=""
price=0.0f
total=0
}
GoodsInfo::~GoodsInfo()
{
}
void GoodsInfo::set_goods(string n,float p,int t)
{
name=n
price=p
total=t
}
string GoodsInfo::goods_name()
{
return name
}
float GoodsInfo::goods_price()
{
return price
}
int GoodsInfo::goods_total()
{
return total
}
void GoodsInfo::goods_disp()
{
cout<<"产品名称"<<name<<"产品单价"<<price<<"库存量"<<total<<endl
}
DrinkMachine::DrinkMachine()
{
v_goods[0].set_goods("美年达",3,20)
v_goods[1].set_goods("苦咖啡",5,10)
v_goods[2].set_goods("娃哈哈纯净水",1.5,20)
v_goods[3].set_goods("悠乐美",2.5,30)
v_goods[4].set_goods("百事可乐",2.5,0)
}
DrinkMachine::~DrinkMachine()
{
}
void DrinkMachine::showMenu()//显示 *** 作界面
{
cout<<"一组温馨提示<*_*>->您投入的金额是"<<moneyctr.money_from_buyer()<<"元"<<endl
cout<<"一组温馨提示<*_*>->请选择商品代码:"<<endl
for(int i=0i<5i++)
{
cout<<i<<" "<<v_goods[i].goods_name()<<" "<<v_goods[i].goods_price()<<"元"<<endl
}
cout<<"5 退款并且退出"<<endl
}
void DrinkMachine::inputmoney()
{
cout<<"一组温馨提示<*_*>->本机只接受 十元、 五元、二元、一元、零点五元的硬币或纸币"<<endl
moneyctr.getmoney()
}
bool DrinkMachine::goodsitem(int select)
{
int number=v_goods[select].goods_total()
if(number>0)
{
if(moneyctr.money_from_buyer()>=v_goods[select].goods_price())//如果钱够
{
float change=moneyctr.money_from_buyer()-v_goods[select].goods_price()
cout<<"你选择的是"<<v_goods[select].goods_name()<<"请取物"<<endl
if(change>0)
{
moneyctr.return_money( change)
}
return true
}
else
{
cout<<"一组温馨提示<*_*>->你的金额不足"<<endl
}
}
else
{
cout<<"一组温馨提示<*_*>->饮料已售完"<<endl
}
return false
}
void DrinkMachine::return_allmoney()
{
cout<<"退款"<<moneyctr.money_from_buyer()<<"元"<<endl
}
void main()
{
DrinkMachine dri
string buf
bool go_on(true),cash_on(true),got_it(true)
cout<<"**************欢迎使用一组自动饮料售货机本自动售货机**************"<<endl
while(go_on)
{
while(cash_on)
{
dri.inputmoney ()
cout<<"一组温馨提示<*_*>->继续投币吗?(yes or no))"
cin>>buf
if(buf=="n"||buf=="no")
{
cash_on=false
}
}
dri.showMenu()
cin>>buf
int select=atoi(buf.c_str ())
if(select==5)
{
dri.return_allmoney ()
go_on=false
}
else
{
got_it=dri.goodsitem(select)
if(got_it)
{
go_on=false
}
else
{
cout<<"一组温馨提示<*_*>->需要其他饮料吗?(yes or no)"
cin>>buf
if(buf=="y"||buf=="yes")
{
cash_on=true
}
else
{
dri.return_allmoney ()
go_on=false
}
}
}
cout<<"谢谢使用"<<endl
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)