设计c语言自动售货机源程序,自动饮料售货机源程序C语言编程

采用C语言编程的自动饮料售货机源程序

#include

#include

#include

class goodsinfo

{

public:

char *name;

float price;

int count;

goodsinfo(char *n,float p,int c)

{

name=new char[strlen(n)+1];

strcpy(name,n);

price=p;

count=c;

}

void shown()

{cout<

cout<

cout<

}

~goodsinfo()

{delete name;}

};

class money

{public:

float exchange;

char enter(float ps)

{

if(ps==10||ps==5||ps==2||ps==1||ps==0.5)

return 't';

else

return 'f';

}

char select(goodsinfo &ob)

{

if(ob.count>0)

return 't';

else

return 'f';

}

char compare(float p,goodsinfo &ob)

{

if(p>=ob.price)

return 't';

else

return 'f';

}

float zhaoling(float p,goodsinfo &ob)

{ exchange=p-ob.price;

return exchange;}

float addmoney(float p)

{

return (p+=p);}

};

main()

{int kele=2,baishi=50,orange=50,coffe=100,water=100;

goodsinfo ob[5]={goodsinfo("可口可乐",2,kele),

goodsinfo("百氏可乐",2,baishi),

goodsinfo("橙汁",3,orange),

goodsinfo("咖啡",5,coffe),

goodsinfo("纯净水",1.5,water)};

int i,n;

float p;

char x,k='y';

do

{

money m;

ob[1].shown();

for( i=0;i<=4;i++)

{

cout<

cout<

}

cout<

cout<

do

{ p=0;

cout<

cin>>p;

cout<

if(m.enter(p)=='t')

x='n';

else

{

p=0;

cout<

cout<

cin>>x;

cout<

if(x=='n'||x=='N')

{

cout<

return 0;

}

}

}while(x=='y'||x=='Y');

cout<

cin>>n;

cout<

do

{if(m.select(ob[n])=='t')

if(http://www.wendangwang.compare(p,ob[n])=='t')

{

ob[n].count--;

cout<

cout<

cout<

cout<

cout<

name<

cout<

cout<