商品信息管理系统c语言课程设计(编辑修改稿)内容摘要:

formation *)malloc(LEN)。 /*开辟一个新单元 */ fscanf(fp,%ld\t\t%s\t\t%s\t\t%d\t\t%f\n,amp。 p1number,amp。 p1name,amp。 p1 leibie,amp。 p1kucun,amp。 p1jiage)。 head=p1。 13 ll:n=n+1。 p2=p1。 p1=(information *)malloc(LEN)。 /*开辟一个新单元 */ fscanf(fp,%ld\t\t%s\t\t%s\t\t%d\t\t%f\n,amp。 p1number,amp。 p1name,amp。 p1 leibie,amp。 p1kucun,amp。 p1jiage)。 p2next=p1。 if(p1number!=0) goto ll。 p2next=NULL。 fclose(fp)。 /*结束读入,关闭文件 */ printf(\n 总有 %d 种商品的信息: \n,n)。 printf(\n 商品编号 \t 商品名称 \t 商品类别 \t 库存数量 \t 商品价格 \n)。 p2=p1=head。 do { printf(%ld\t\t%s\t\t%s\t\t%d\t\t%.2f\n,p1number,p1name,p1lei bie, p1kucun,p1jiage)。 p1=p1next。 } while(p1!=NULL)。 getch()。 system(cls)。 /*清屏 */ return (head)。 } creat 创建链表函数 information *creat(void)/*函数 creat,功能:创建链表,此函数带回一个指向链表头的指针 */ { information *head。 information *p1,*p2,*p3。 int i。 system(cls)。 /*清屏 */ n=0。 p1=p2=p3=(information *)malloc(LEN)。 head=p3。 /*开辟一个新单元 */ repeat1: printf(请输入 7 位商品编号(退出请 按 “ 0” ): )。 /*输入编号,编号应大于 0*/ scanf(%d,amp。 p1number)。 if(p1number==0) goto end。 14 else { while(p1number1000000||p1number=10000000) { printf(输入错诨 !)。 goto repeat1。 } p3=head。 if(n0) { for(i=0。 in。 i++) { if(p1number!=p3number) p3=p3next。 else { printf(编号重复 ,请重输 !\n)。 goto repeat1。 /*当输入的编号已经存在,程序报错,返回前面重新输入 */ } } } } printf(请输入商品名: )。 scanf(%s,amp。 p1name)。 /*输入商品商品名 */ printf(请输入商品类别: )。 /*输入商品类别 */ scanf(%s,amp。 p1leibie)。 printf(请输入商品库存(大于 0): )。 /*输入商品库存 */ scanf(%d,amp。 p1kucun)。 while(p1kucun0) { printf(输入错诨,请重新输入商品数量 )。 /*输入错诨,重新输入商品库存直到正确为止 */ scanf(%d,amp。 p1kucun)。 } printf(请输入商品价格(大于 0): )。 /*输入商品价格 */ scanf(%f,amp。 p1jiage)。 while(p1jiage0) { printf(输入错诨,请重新输入商品价格 )。 scanf(%f,amp。 p1jiage)。 }/*输入错诨,重新输入商品价格直到正确为止 */ head=NULL。 while(p1number!=0) 15 { n=n+1。 if(n==1) head=p1。 else p2next=p1。 p2=p1。 p1=(information *)malloc(LEN)。 repeat2:printf(请输入 7 位商品编号(退出请按 “ 0” ): )。 scanf(%d,amp。 p1number)。 /*输入编号,编 号应大于 0*/ if(p1number==0) goto end。 else { while(p1number1000000||p1number=10000000) { printf(输入错诨 !)。 goto repeat2。 } p3=head。 if(n0) { for(i=0。 in。 i++) { if(p1number!=p3number) p3=p3next。 else { printf(编号重复 ,请重输 !\n)。 goto repeat2。 /*当输入的编号已经存在,程序报错,返回前面重新输入 */ } } } } printf(请输入商品名: )。 scanf(%s,amp。 p1name)。 /*输入商品商品名 */ printf(请输入商品类别: )。 /*输入商品类别 */ scanf(%s,amp。 p1leibie)。 printf(请输入商品库存(大于 0): )。 /*输入商品库存 */ scanf(%d,amp。 p1kucun)。 while(p1kucun0) { printf(输入错诨,请重新输入商品数量 )。 /*输入错诨,重新输入商品库存直到正 确为止 */ 16 scanf(%d,amp。 p1kucun)。 } printf(请输入商品价格(大于 0): )。 /*输入商品价格 */ scanf(%f,amp。 p1jiage)。 while(p1jiage0) { printf(输入错诨,请重新输入商品价格 )。 scanf(%f,amp。 p1jiage)。 }/*输入错诨,重新输入商品价格直到正确为止 */ } end: p1=head。 p3=p1。 p2next=NULL。 /*链表结尾 */ printf(\n\n 输入的商品数为 :%d 个 !\n,n)。 getch()。 system(cls)。 /*清屏 */ return(head)。 } search 函数 information *search(information *head)/*函数 search,功能:查询商品信息 */ { information *p1,*p2。 int a,b。 long c。 char t[100]。 system(cls)。 /*清屏*/ if(head==NULL) { printf(\n\n\n 没有仸何商品资料,请先建立商品资料 !\n)。 getch()。 system(cls)。 return(head)。 } p2=p1=head。 lp2: { system(cls)。 /*清屏 */ printf(\n\n\n\n)。 printf( $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n)。 printf( $$\n)。 printf( $$ 1 *按商品编号查询 \n)。 printf( $$\n)。 17 printf( $$\t 2 *按商品名称查询 \n)。 printf( $$\n)。 printf( $$\t\t 3 *按商品类别查询 \t\t\t $$\n)。 printf( $$\t\t\t\t\t\t\t $$\n)。 printf( \t\t\t 4 *查询需迚货商品 (库存小于 50) $$\n)。 printf(\t\t\t\t\t\t\t\t $$)。 printf( \t\t\t\t\t\t 0 *退出 \t\t $$\n)。 printf(\t\t\t\t\t\t\t\t $$)。 printf(\n\t\t\t\t $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$)。 printf(\n\n\n\n\n\n)。 printf(请选择您所要的查询方式 :)。 scanf(%d,amp。 a)。 /*选择操作 */ } switch(a)/*用 switch 诧句实现功能选择 */ { /*============================================================*/ case 1: { system(cls)。 /*清屏 */ lp3:printf(请输入所要查询商品的 7 位编号 (按 0 返回选择界面 ):)。 lp10:scanf(%ld,amp。 c)。 b=0。 if(c==0) goto lp2。 while(c1000000||c=10000000) { printf(输入错诨 \n)。 goto lp3。 } while(c!=0) { p1=head。 while(c!=p1numberamp。 amp。 p1next!=NULL) { p2=p1。 p1=p1next。 } if(c==p1number) { printf(\n 商品编号 \t 商品名称 \t 商品类别 \t 库存数量 \t 商品价格 \n)。 printf(%ld\t\t%s\t\t%s\t\t%d\t\t%.2f\n\n,p1number,p1name,p1leibie,p1kucun, p1jiage)。 b=1。 } 18 if(b==0) printf(丌存在 %d 该商品 !\n,c)。 printf(请输入要查询的商品的编号 (按 0 返回选择界面 ):)。 goto lp10。 } } break。 /*============================================================*/ case 2: { system(cls)。 /*清屏 */ lp7:printf(输入所要查询商品的名称 (按 0 返回选择界面 ):)。 scanf(%s,amp。 t)。 b=0。 if(strcmp(t,0)==0) goto lp2。 while(strcmp(t,0)!=0) { p1=head。 if(strcmp(t,p1name)!=0amp。 amp。 p1next!=NULL) { p2=p1。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。