下吧
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct prod
{
char num[10];
char name[10];
char leixing[12];
char guige[10];
char danwei[10];
int sum;
float prize;
char jihuo[12];
char youxiao[12];
struct prod *next;
}PRODUCT,*PLINK;
char *menu[]={" 1.产品信息的输入: ",
" 2.产品信息的修改:",
" 3.产品信息的删除: ",
" 4.根据产品名称查询: ",
" 5.显示全部产品信息: ",
" 6.按参考价格从小到大显示产品信息:",
" 7.显示全部过期产品信息: ",
" 8.增加产品信息: ",
" 9.退出系统: "};
int menu_select()
{
char c[3];
int a;
int i;
for(i=0;i<9;i++)
printf("%s\n",menu[i]);
do
{
scanf("%s",c);
a=atoi(c);
}while(a<0||a>10);
return a;
}
void print(PRODUCT *head);
PRODUCT *creat();
PRODUCT *del(PRODUCT *h);
PRODUCT *modify(PRODUCT *h);
void inquire(PRODUCT *h);
void printguoqi(PRODUCT *h);
PRODUCT *insert(PRODUCT *h);
void sortprint(PRODUCT *h);
void main()
{
PRODUCT *head=NULL;
for(;;)
{
switch(menu_select())
{
case 1:head=creat();break;
case 2:head=modify(head);break;
case 3:head=del(head);break;
case 4:inquire(head);break;
case 5:print(head);break;
case 6:sortprint(head);break;
case 7:printguoqi(head);break;
case 8:head=insert(head);break;
case 9:exit(0);
}
}
}
PRODUCT *creat()
{
PRODUCT *p,*h=NULL;
int i;
printf("请输入产品编号时,以#结束:\n");
printf("!!!请注意,输入数据时不可以按空格:!!!\n");
do
{
p=(PLINK)malloc(sizeof(PRODUCT));
printf("请输入产品编号:\n");
scanf("%s",p->num);
if(strcmp(p->num,"#")==0)
break;
printf("请输入产品名称:\n");
scanf("%s",p->name);
printf("请输入产品类型编号:\n");
scanf("%s",p->leixing);
printf("请输入产品规格:\n");
scanf("%s",p->guige);
printf("请输入产品计量单位:\n");
scanf("%s",p->danwei);
printf("请输入产品的数量:\n");
scanf("%d",&p->sum);
printf("请输入产品的参考价格(可输小数):\n");
scanf("%f",&p->prize);
printf("请输入产品进货日期(年.月.日):\n");
scanf("%s",p->jihuo);
printf("请输入产品的有效期:\n");
scanf("%s",p->youxiao);
p->next=h;
h=p;
}while(1);
return h;
}
void print(PRODUCT *head)
{
PRODUCT *p;
p=head;
if(p==NULL)printf("|产品编号|名称|产品类型编号|产品规格|计量单位|数量|参考价格|进货日期|有效日期|\n");
while(p)
{
printf("|编号|名称|产品类型编号|产品规格|计量单位|数量|参考价格|进货日期|有效日期|\n");
printf("|%5s|%4s|%-12s|%8s|%4s|%8d|%9f|%10s|%10s\n",p->num,p->name,p->leixing,p->guige,p->danwei,p->sum,p->prize,p->jihuo,p->youxiao);
p=p->next;
}
}
PRODUCT *del(PRODUCT *h)
{
PRODUCT *p,*q;
char number[10];
printf("请输入你要删除的产品的编号:\n");
scanf("%s",number);
if(h==NULL)
p=h;
while(strcmp(number,p->num)&&p)
if(!strcmp(number,p->num))
{
if(p==h)h=h->next;
else q->next=p->next;
}
return h;
}
PRODUCT *modify(PRODUCT *h)
{
PRODUCT *p,*q;
char number1[10];
printf("请输入你要修改的产品的编号:\n");
scanf("%s",number1);
p=h;
while(p)
{
if(strcmp(number1,p->num)==0)
{
printf("你要修改的产品信息如下:\n");
printf("|编号|名称|产品类型编号|产品规格|计量单位|数量|参考价格|进货日期|有效日期|\n");
printf("|%5s|%4s|%-12s|%8s|%4s|%8d|%9f|%10s|%10s\n",p->num,p->name,p->leixing,p->guige,p->danwei,p->sum,p->prize,p->jihuo,p->youxiao);
printf("请重新填写此产品的信息:\n");
printf("请输入产品编号:\n");
scanf("%s",p->num);
printf("请输入产品名称:\n");
scanf("%s",p->name);
printf("请输入产品类型编号:\n");
scanf("%s",p->leixing);
printf("请输入产品规格:\n");
scanf("%s",p->guige);
printf("请输入产品计量单位:\n");
scanf("%s",p->danwei);
printf("请输入产品的数量:\n");
scanf("%d",&p->sum);
printf("请输入产品的参考价格(可输小数):\n");
scanf("%f",&p->prize);
printf("请输入产品进货日期(年.月.日):\n");
scanf("%s",p->jihuo);
printf("请输入产品的有效期:\n");
scanf("%s",p->youxiao);
printf("修改产品信息成功!\n");
break;
}
}
printf("你要修改的产品信息不存在!!\n");
return h;
}
void inquire(PRODUCT *h)
{
PRODUCT *p;
char number2[10];
printf("请输入你要查询的产品的名称:\n");
scanf("%s",number2);
p=h;
while(p)
{
if(strcmp(number2,p->name)==0)
{
printf("|编号|名称|产品类型编号|产品规格|计量单位|数量|参考价格|进货日期|有效日期|\n");
printf("|%5s|%4s|%-12s|%8s|%4s|%8d|%9f|%10s|%10s\n",p->num,p->name,p->leixing,p->guige,p->danwei,p->sum,p->prize,p->jihuo,p->youxiao);
break;
}
p=p->next;
}
printf("你要查询的产品信息不在库存中!!!\n");
}
void printguoqi(PRODUCT *h)
{
PRODUCT *p;
int i=0;
if(h==NULL)printf("对不起!!您的仓库中还没有产品!\n");
else
{
p=h;
while(p)
{
if(strcmp(p->jihuo,p->youxiao)>0)
{
printf("|编号|名称|产品类型编号|产品规格|计量单位|数量|参考价格|进货日期|有效日期|\n");
printf("|%5s|%4s|%-12s|%8s|%4s|%8d|%9f|%10s|%10s\n",p->num,p->name,p->leixing,p->guige,p->danwei,p->sum,p->prize,p->jihuo,p->youxiao);
i++;
}
p=p->next;
}
if(i==0)printf("您的库存中的产品都还没有过期!!!\n");
}
}
PRODUCT *insert(PRODUCT *h)
{
PRODUCT *r;
do
{
r=(PLINK)malloc(sizeof(PRODUCT));
printf("请输入产品编号:\n");
scanf("%s",r->num);
if(strcmp(r->num,"#")==0)
break;
printf("请输入产品名称:\n");
scanf("%s",r->name);
printf("请输入产品类型编号:\n");
scanf("%s",r->leixing);
printf("请输入产品规格:\n");
scanf("%s",r->guige);
printf("请输入产品计量单位:\n");
scanf("%s",r->danwei);
printf("请输入产品的数量:\n");
scanf("%d",&r->sum);
printf("请输入产品的参考价格(可输小数):\n");
scanf("%f",&r->prize);
printf("请输入产品进货日期(年.月.日):\n");
scanf("%s",r->jihuo);
printf("请输入产品的有效期:\n");
scanf("%s",r->youxiao);
r->next=h;
h=r;
}while(1);
return h;
}
void sortprint(PRODUCT *h)
{
PRODUCT *p,*q,*t,*h1;
h1=h->next;
h->next=NULL;
while(h1!=NULL)
{
t=h1;
h1=h1->next;
p=h;
q=h;
while(t->prize>p->prize&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==q)
{
t->next=p;
h=t;
}
else
{
t->next=p;
q->next=t;
}
}
print(h);
printf("排序成功!!!\n");
}
温馨提示:内容为网友见解,仅供参考