湖北汽车工业学院C语言课程设计——商品销售信息管理系统源代码_第1页
湖北汽车工业学院C语言课程设计——商品销售信息管理系统源代码_第2页
湖北汽车工业学院C语言课程设计——商品销售信息管理系统源代码_第3页
湖北汽车工业学院C语言课程设计——商品销售信息管理系统源代码_第4页
湖北汽车工业学院C语言课程设计——商品销售信息管理系统源代码_第5页
免费预览已结束,剩余22页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include<stdio.h>#include<stdlib.h>#include<string.h>#include<malloc.h>struct productint num;char productname20;float price;char place30;int storage;struct product *next;*head,*p1,*p2;struct timeC 语言课程设计 商品销售信息管理系统/ 定义商品数据结构/ 商品编号/ 商品名称/ 商品售价/ 商品产地/ 商品库存/ 定义主结构体数组和备用结构体数组及指针/

2、 定义时间结构体int year;int month;int day;struct sellint ID;char customername20;/ 定义销售数据结构int num;int count;char date10;struct sell * next1;*head1;/*/ 顾客代码/ 顾客姓名/ 商品编号/ 销售数量/ 日期定义头指针head,缓冲指针p1,以及尾指针p2函数申明 */void Enter_productmessage();void Creat();void Search_num();void Search_customername();void Printf_c

3、ustomername();void Search_date();void Save_product();void Save_customername();void Exit();/*int select()/ 导入商品信息/ 输入销售记录/ 按编号查询销售历史/ 按顾客姓名查询购买历史/ 显示顾客信息/ 计算时间段内销售总额/ 保存销售信息/ 保存顾客信息/ 退出程序主菜单 */int c;printf("tt* 欢迎使用商品销售管理程序*n");printf("ttT1123-5 班 胡 军 一分耕耘一分收获n");printf("n n&

4、quot;);printf("n");printf("tt*printf("tt*n")printf("tt*1: 导入商品信息*n");printf("tt*2:输入销售记录*n");printf("tt*3:按编号查询销售历史*n");printf("tt*4: 按顾客姓名查询购买历史*n");printf("tt*5:计算时段内各销售总额*n");printf("tt*6:显示顾客信息*n");printf("

5、tt*7:保存销售信息*n");printf("tt*8:保存顾客信息*n");printf("tt*0:退出*n");printf("tt* 欢迎使用商品销售管理系统*n");printf("tt*printf("n n");printf("tt 请输入您的选择 (08 的整数 ): ");scanf("%d",&c);return c;/*主函数*/int main()for(;)switch(select()case 1:system(&qu

6、ot;cls");Enter_productmessage();break;case 2:system("cls");Creat();break;case 3:system("cls");Search_num();break;case 4:system("cls");Search_customername();break;case 5:system("cls");Search_date();break;case 6:system("cls");Printf_customername()

7、;break;case 7:system("cls");Save_product();break;case 8:system("cls");Save_customername();break;case 0:system("cls");Exit();break;default : system("cls");printf("nnnnnn");printf("tt*n");printf("tt*输 入 错 误 ! 请 重 新 输 入 您 的 选 择 (08 的 整 数

8、)*n");printf("tt*请 按 Enter 键 返 回 !*n");printf("tt*n");getchar();getchar();system("cls");return 0;/*/int judgech(char *a)/ 判断是否为汉字int i,flag;for(i=0;ai!='0'i+)if(ai>=0) flag=0;break;elseflag=1;return flag;int judgedate(char date10)/ 判断日期是否合法int i,year,mon

9、th,day,s1=0; 日期格式输入正确则 s1=1,否则 s1=0 for(i=0;i<10;i+)if(datei='0') s1=0;break; if(date4=' -'&&date7=' -')if(strlen(date)=10) year=1000*(date0 -48)+100*(date1 -48)+10*(date2 -48)+(date3 -48);/ 年月日month=10*(date5 -48)+(date6 -48);day=10*(date8 -48)+(date9 -48);if(i=10

10、)if(year%4=0&&month=2&&day>0&&day<=29)s1=1;else if(year%4!=0&&month=2&&day>0&&day<=28)s1=1;elseif(month=1|month=3|month=5|month=7|month=8|month=10|month=12)&&d ay>0&&day<=31) s1=1;else if(month=4|month=6|month=9|month=

11、11)&&day>0&&day<=30) s1=1;return s1;void file() / 读入文件操作int i=0,m=0,k=1,j=1,c=1,o=1,v=1;FILE *fp;char 30;printf(" 请输入读入文件路径:");rewind(stdin);gets();rewind(stdin);p1=p2=head=(struct product*)malloc(sizeof(struct product); if(fp=fopen(,"r+")=NULL)printf("

12、tt*n");printf("tt* 导入信息文件错误!请检查文件路径!printf("tt*n");getchar();system("cls");Enter_productmessage();*n");printf("*n");printf(" 编号 (1-10 的整数 ) 名称 (汉字 ) n");价格(数字 )品信息产地(汉字) 库存数量printf(”*n");while(!feof(fp)p1=(struct product*)malloc(sizeof(stru

13、ct product);p2->next=p1;p1->next=NULL;p2=p1;fscanf(fp,"%d%s%f%s%d",&p2->num,p2->productname,&p2 ->price,p2->place,&p2->storage );while(k=1)if(p2 ->num>10|p2 ->num<=0)printf("t*n");printf("tt第个商品编码!请重新输入(1-10):",i+1);rewind(st

14、din);scanf("%d",&p2 ->num);k=1;else k=0;while(j=1)if(judgech(p2 ->productname)=0)printf("tt第dj商品名称错误!请重新输入(汉字):",i+1);rewind(stdin);scanf("%s",p2->productname);j=1;else j=0;while(o=1)if(p2 ->price<=0)printf("tt第dj商品价格错误!请重新输入价格(>0):",i+1)

15、;rewind(stdin);scanf("%f",&p2 ->price);o=1;else o=0;while(c=1)if(judgech(p2 ->place)=0)printf("tt第个商品产地格式错误!请重新输入(汉字):",i+1);rewind(stdin);scanf("%s",p2->place);c=0;else c=0;while(v=1)if(p2 ->storage!=1000)printf("t*n");printf("tt第dj商品数量错误

16、!请输入1000:",i+1);rewind(stdin);scanf("%d",&p2 ->storage);v=1;else v=0;>plaprintf("t% -12d%-15s %-15.2f%-15s%-12dn",p2 ->num,p2->productname,p2 ->price,p2 ce,p2->storage);fclose(fp);void comp()FILE *fp;int i=0,n,k=1,m=1,c=1,l=1,d=1;char 20,a;printf("

17、t 请输入商品信息保存路径:");rewind(stdin);gets();p1=p2=head=(struct product*)malloc(sizeof(struct product);if(fp=fopen(,"a+")=NULL)printf("tt*n");*n");printf("tt* 不能打开文件!请检查文件路径!printf("tt*n");getchar();system("cls");Enter_productmessage();printf("nnn

18、");printf("tt* printf("tt* printf("tt* printf("tt* printf("tt*n");若输入路径与从文件导入商品信息路径相同并已导入十个商品信息,请不要再导入 !注意商品编号不要和已导入的编码重复*n");!*n");*n");*n");printf("nnn");getchar();system("cls");!nn");产地 (汉字 ) 库存数量 n");printf(&quo

19、t;t 已从文件导入的个数和要输入的个数和不超过十printf("t 请输入要导入的销售记录个数 :");scanf("%d",&n);if(n>0)dop1=(struct product*)malloc(sizeof(struct product);p2->next=p1;p1->next=NULL;p2=p1;printf("*n");printf(" 编号 (整数 ) 名称(汉字) 价格 (数字 )scanf("%d%s%f%s%d",&p2->num,p2

20、->productname,&p2 ->price,p2->place,&p2->storage); while(k=1)if(p2 ->num>10|p2 ->num<=0)printf("t*n");printf("tt 商品编码 !请重新输入 (1-10):");rewind(stdin);scanf("%d",&p2 ->num);k=1;else k=0;while(m=1)if(judgech(p2 ->productname)=0)pri

21、ntf("tt 商品名称错误!请重新输入(汉字):");rewind(stdin);scanf("%s",p2->productname);m=1;else m=0;while(l=1)if(p2 ->price<=0)printf("tt 商品价格错误!请重新输入价格 (>0):");rewind(stdin);scanf("%f",&p2 ->price);l=1;else l=0;while(c=1)if(judgech(p2 ->place)=0)printf(&

22、quot;tt 商品产地格式错误!请重新输入(汉字):");rewind(stdin);scanf("%s",p2->place);c=1;else c=0;while(d=1)if(p2 ->storage!=1000)printf("t*n");printf("tt 商品数量错误 !请输入 1000:");rewind(stdin);scanf("%d",&p2 ->storage);d=1;else d=0;p2=head->next;fprintf(fp,"

23、;n% -6d%-6s%-6.2f%-6s%-6dn",p2 ->num,p2->productname,p2 ->price,p2 ->place, p2->storage);printf("n% -6d%-6s%-6.2f%-6s%-6dn",p2 ->num,p2 ->productname,p2 ->price,p2->place,p2- >storage);printf("tt 是否继续输入信息(Y/N)?n");getchar();a=getchar();while(a=&

24、#39;Y'|a='y');fclose(fp); if(n=0)/ 关闭文件夹printf("tt 不从键盘输入入信息!");getchar();getchar(); system("cls");fclose(fp);/ 关闭文件夹void Enter_productmessage() / 导入销售信息int a;printf("t* printf("t* printf("t* printf("t* printf("t* printf("t*n");请输入 1

25、0 种产品的信息-编号、名称、价格、产地、数量1: 通过文件导入(推荐)!2: 通过键盘输入 !*n");请输入您的选择 (1 或 2): ");scanf("%d",&a);getchar();system("cls");if(a!=1&&a!=2)printf("tt 输入错误 ! 请重新输入您的选择(1 或 2):");scanf("%d",&a);switch(a)case 1:system("cls"); file();break;c

26、ase 2:system("cls"); comp();break;printf("* n");printf("t* printf("t* printf("t*n");数据类信息操作成功 !请按 Enter 键继续 !*n");*n");*n");*n");*n");getchar();getchar();system("cls");/ 输入销售信息函数void Creat() int i=0,k=1,code;char a;struct sel

27、l *p3,*p4;srand(0);code=1+rand()%90;p3=p4=head1=(struct sell *)malloc(sizeof(struct sell);p3=head1;printf("tt 请输入销售记录:n");printf(" dop3=(struct sell *)malloc(sizeof(struct sell);p4->next1=p3;p3->next1=NULL;p4=p3;printf(" 顾客姓名(汉字) 商品编号(YYYY-MM -DD)n");printf(" / 提示

28、输入记录 n");(1-10 的整数 ) 销售数量 (数字 )n");scanf("%s%d%d%s",p4->customername,&p4 ->num,&p4 ->count,p4->date); 记录销售日期/ 输 入doif(judgech(p4 ->customername)=0) printf("t*n");printf("tt 顾客名字输入错!请重新输入顾客名字(汉字 ):");scanf("%s",p4->customerna

29、me);rewind(stdin);k=1;elsek=0;while(k=1);doif(p4->num>10|p4 ->num<=0) printf("t*n");printf("tt 商品编码 !请重新输入 (1-10):");scanf("%d",&p4 ->num);rewind(stdin);k=1;else k=0;while(k=1);doif(p4->count>1000|p4 ->count<0) printf("t*n");prin

30、tf("t 销售商品数量错误 !请输入 (0-1000):");scanf("%d",&p4 ->count);rewind(stdin);k=1;else k=0;while(k=1);doif(judgedate(p4 ->date)!=1)printf("t*n");printf("t 输入日期不合法!请重新输入(YYYY-MM -DD):");scanf("%s",p4->date);rewind(stdin);k=1;else k=0;while(k=1);p

31、4->ID=code+i;i+;printf("nn");printf(" 是否继续输入销售记录(Y/N)?n");getchar();a=getchar();while(a='Y'|a='y');system("cls");printf("nnnn");printf("t*printf("t*printf("t*n");*n");销售信息输入成功 ! 按 Enter 键继续 !*n");getchar();getch

32、ar();system("cls");return;void Search_num() / 根据产品编号查询产品的销售历史int num,flag=1,i=0;struct sell *p3;struct product *p;printf("tt 请输入商品编号 (1-10 的整数 ):");scanf("%d",&num);getchar();system("cls");销售数量销售总额销售日期 n"); n");printf(" 顾客姓名 商品编号printf("

33、; p3=head1;p=head;while(p3!=NULL)if(p3->num=num)p=head;while(p!=NULL) if(p->num=num) break;elsep=p->next;printf(" %-15s%-13d%-13d%-13.2f%-10sn",p3 ->customername,p3 ->num,p3 ->count,p ->pric e*p3 ->count,p3 ->date);flag=0;p3=p3->next1;if(flag=1)printf("tt

34、 printf("tt printf("tt printf("tt*n");无此编码商品销售记录! 请查实后再输入 !请按 Enter 键返回 !*n");*n");*n");getchar(); system("cls");return;n");printf(" printf("tt*n");printf("tt* 销售记录查询完毕!请按 Enter 键返回 !*n");printf("tt*n");getchar();ge

35、tchar();system("cls");return;void Search_customername() int k=1,m=0;float a=0;char name20,b;struct product *p;struct sell *p3;/ 根据顾客姓名查询购买历史p3=head1;p=head;printf("tt*n");printf("ttt 请输入顾客姓名(汉字):");scanf("%s",name);getchar();system("cls");if(head1 -&

36、gt;next1=NULL)printf("tt printf("tt printf("tt*n");销售记录为空!请按Enter键返回!!*n");getchar();getchar();system("cls");return ;doif(judgech(name)=0)printf("t*n");printf("tt 顾客名字输入错!请重新输入顾客名字(汉字):");rewind(stdin);scanf("%s",name);rewind(stdin);k=

37、1;*n");elsek=0;while(k=1);if(judgech(name)=1)printf(" 顾客姓名(汉字 ) 顾客代码商品编号 购买数量购买总额购买日期(YYYY-MM -DD)n");printf(" n");while(m!=1)if(strcmp(name,p3 ->customername)=0) m=1;while(p!=NULL)if(p3->num=p->num)printf("%5s%15d%10d%10d%15.2f%14sn",p3 ->customername,

38、p3 ->ID,p3->num,p3 ->count, p3->count*p ->price,p3->date);break;else p=p->next;else p3=p3->next1;if(p3=NULL)break;if(m=1)printf(" - printf("t* printf("t* printf("t*n");查询完毕!请按Enter键返回!!*n");n");*n");if(m=0)printf("tt printf("t

39、t printf("tt*n");getchar();system("cls");return;*n");不存在此顾客! 请按 Enter 键继续 !*n");printf("tt 是否记录该顾客销售记录!n");printf("tt 请输入选择(Y/N):");rewind(stdin);b=getchar();if(b='n'|b='N')getchar();system("cls"); return;if(b='y'|b=

40、'Y') getchar();Creat();void Search_date() / 计算时间段内各个商品的销售总额 int n=0;float temp=0;char a10,b10,c10;struct sell *p3;struct product *p;p3=head1->next1;p=head->next;getchar();system("cls");if(head1 ->next1=NULL) printf("tt printf("tt printf("tt*n");无销售记录! 请

41、按 Enter 键返回 !*n");getchar();system("cls");return ;*n");printf("tt 请输入开始日期 (YYYY-MM -DD):");gets(a);doif(judgedate(a)!=1)printf("tt*n");printf("tt 输入日期不合法!请重新输入 (YYYY-MM -DD):");gets(a);system("cls");n=1;elsen=0;while(n=1);printf("tt*n&

42、quot;);printf("tt请输入结束日期 (YYYY-MM -DD):");gets(b);system("cls");doif(judgedate(b)!=1)printf("tt*n");printf("tt 输入日期不合法,请重新输入 (YYYY-MM -DD):");gets(b);system("cls");n=1;elsen=0;while(n=1);doif(strcmp(a,p3 ->date)<=0)&&(strcmp(b,p3 ->d

43、ate)>=0) n=1;break;else p3=p3->next1;if(p3=NULL)break;while(n!=1);while(1)p3=head1 ->next1;->if(strcmp(a,p3 ->date)>0&&strcmp(b,p3 ->date)>0)|(strcmp(a,p3 ->date)<0&&strcmp(b,p3 date)<0)|(strcmp(a,b)>0)printf(" 时间断不包括销售日期 !");Search_date(

44、);getchar();return;else p3=p3->next1;if(p3=NULL)break;if(n=1)printf("tt 销售记录如下:n");printf("tt 时间:$至$行启,功;销售总额);printf("t 商品编号 (1-10 的整数 )商品名(汉字)n");printf("n nwhile(p!=NULL)p3=head1 ->next1;if(p3->num=p->num)temp+=(int)p3 ->count*(float)p ->price;strcp

45、y(c,p->productname);printf("tt% -20d%-20s%.2fn",p3 ->num,c,temp); p=p->next;printf("n n");printf("tt*n");printf("tt*查询完毕 !请按 Enter 键继续 !*n");printf("tt*n");getchar();getchar();system("cls");return;void Printf_customername()/ 显示所有顾客

46、的姓名int n=1;struct sell *p3;p3=head1->next1;if(p3!=NULL)/ 用来显示所有顾客的姓名printf("tt 顾客姓名如下:n");printf("tt*n");printf("ttttt 姓名 :n");doprintf("ttttt %sn",p3 ->customername);p3=p3->next1;printf("ttprintf("ttwhile(p3!=NULL);,*,*printf("ttprintf

47、("tt顾客姓名查询完毕!请按Enter 键继续 !*n");getchar();getchar(); system("cls");return;*n");elseprintf("tt printf("tt printf("tt*n");顾客链表为空! 没有顾客销售记录!*n");getchar();system("cls");return;*n");void Save_product() FILE *fp;char 30;struct product *p;struct sell *p3;p3=head1->next1;p=head->next;/ 保存销售信息记录/ 定义文件指针printf(" 请输入保存路径:n");rewind(stdin);gets();rewind(stdin);if(fp=fopen(,"a+")=NULL) / 打开文件 printf("tt printf("tt printf("tt*n");保存文件失败!按Enter键返

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论