大家帮忙看看,也就是逻辑问题,出了点问题,看了一个下午,没有看出来,求帮忙!!
#include <iostream>#include <string>
using namespace std;
#define MaxSize 10
#define OK 1
#define NO 0
struct goods //商品结构体
{
string num;
int date;
};
struct SeqStack
{
struct goods date[MaxSize];
int top;
};
int paixu(SeqStack *s,goods x); //函数声明
void InitSeqStack(SeqStack *s) //置空栈
{
s->top=-1;
}
int isempty(SeqStack *s) //判断是否空栈
{
return (s->top==-1?OK:NO);
}
int isfull(SeqStack *s) //判断栈满
{
return(s->top==MaxSize?OK:NO);
}
void push(SeqStack *s,goods x) //入栈
{
if(isfull(s))
{
cout<<"货架已满,将返回主菜单"<<endl;
return ;
}
if(paixu(s,x)) return ;
s->top++;
s->date[s->top]=x;
cout<<" 货物成功放入货架 "<<endl;
}
void input(SeqStack *s) //输入商品信息
{
int a;
string st;
struct goods gd;
cout<<" 请输入商品号:";
cin>>st;
do
{
gd.num=st;
cout<<" 请输入商品日期:";
cin>>a;
cout<<" 停止放入货物请按(0)"<<endl;
gd.date=a;
if(a==0)
break;
push(s,gd);
}
while(a!=0);
}
int paixu(SeqStack *s,goods x) //排序
{
struct goods temp;
if(isempty(s)) return 0;
if(s->date[s->top].date < x.date) //将日期小的放在上面
{
temp=s->date[s->top];
s->date[s->top]=x;
s->top++;
s->date[s->top]=x;
cout<<" 商品入架成功"<<endl;
return 1;
}
else return 0;
}
void output(SeqStack *s) //出栈(卖出货物)
{
int n;
goods gd;
if(isempty(s))
{
cout<<" 货物已经卖空,或者没有将商品上架"<<endl<<endl<<endl;
return;
}
cout<<" 请输入需要卖出商品的个数"<<endl;
cin>>n;
cout<<" 本次卖出的货物信息如下:"<<endl;
for(int i=s->top;i>=s->top-n;i--)
{
gd=s->date[i];
cout<<"商品号:"<<gd.num<<" ";
cout<<"商品日期:";
cout<<gd.date<<endl;
s->top--;
}
}
void look(SeqStack *s) //打印货架信息
{
goods gd;
if(isempty(s))
{
cout<<" 货物已经卖空,或者没有将商品上架"<<endl<<endl<<endl;
return;
}
cout<<" 货架信息如下:"<<endl;
for(int i=s->top;i>=0;i--)
{
gd=s->date[i];
cout<<"商品货号:"<<gd.num<<" ";
cout<<"商品日期:"<<gd.date<<endl;
}
}
void wlcome()
{
cout<<" ==欢迎使用网络101小组制作的货架管理系统== "<<endl;
cout<<" ========================================= "<<endl;
cout<<" || [1]--添加货物 "<<endl;
cout<<" || [2]--卖出货物 "<<endl;
cout<<" || [3]--察看货物 "<<endl;
cout<<" || [0]--退出系统 "<<endl;
cout<<"____________________________________________"<<endl;
cout<<" || 版本:1.00 仿制必究 日期:2010/10/13 "<<endl;
cout<<" =========================================="<<endl;
}
int main()
{
struct SeqStack *s=NULL;
s=new SeqStack; //开辟一个结点
InitSeqStack(s);
int temp;
do
{
wlcome();
cout<<" 请输入您的选择:"<<endl;
cin>>temp;
if(temp<0||temp>4)
{
cout<<" 您输入的选择错误,请重新选择。"<<endl;
continue;
}
switch(temp)
{
case 1: input(s); break;
case 2: output(s); break;
case 3: look(s); break;
case 0:
delete s;
cout<<"欢迎下次继续使用本系统"<<endl;
return 0;
}
}
while(temp!=0);
return 0;
}