商品销售管理系统设计_第1页
商品销售管理系统设计_第2页
商品销售管理系统设计_第3页
商品销售管理系统设计_第4页
商品销售管理系统设计_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

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

文档简介

1、.:.;、商品销售管理问题描画:知一公司有10种产品产品编号,产品称号,产品价钱,产品产地,库存数量最开场为1000个,设计一程序,完成以下功能:1)销售:从键盘输入顾客姓名,销售数量、销售日期,实现销售功能。需求判别产品能否存在,销售数量能否小于库存数量,销售日期格式能否合法格式为:YYYY-MM-DD,如2021-01-022)能根据产品编号查询产品的销售历史3)计算时间段内各个产品的销售总额4)能根据顾客姓名,查询购买历史5)能显示一切顾客的姓名提示:定义一个日期构造体保管日期,详细信息为:年、月、日判别存款日期和取款日期的格式能否合法时,需求判别长度能否为10,第5位和第8位能否为-,

2、字符,将1-4位表示的年份,6-7位表示的月份,9-10位表示的日期分别转换成整数。判别能否满足构成日期的条件闰年月份只能是1-12之间的数,假设是闰年,二月可以是29天否那么不能大于28,1,3,5,7,8,10,12月可以是31天,其他只能小于等于30建议写成函数。定义一个构造体数组保管10种产品信息,详细信息为:产品编号,产品称号,产品价钱,产品产地,库存数量最开场为1000个定义一个链表,保管销售信息,详细为:顾客代码,销售数量、销售日期。定义一个链表保管顾客信息,详细为:顾客代码,顾客姓名当输入销售信息时查询顾客链表,假设在链表中存在该姓名的顾客记录,那么将其代码在该销售链表中插入一

3、条记录,假设不存在,那么在顾客链表中插入一条记录,顾客代码需求自动生成。 #include stdio.h /*I/O函数*/#include stdlib.h /*规范库函数*/#include string.h/*字符串函数*/#include ctype.h /*字符操作函数*/#include time.h /*时钟函数*/#include cstdlib#include conio.hint x,k;/*定义全局变量用于保管当前商品种类*/struct product /*定义商品数据构造*/ int num; /*商品编号*/ char name20; /*商品称号*/ float

4、 price; /*商品售价*/ char place10; /*商品称号*/ int storage; /*商品库存*/_product10,product110;/定义主构造体数组和备用构造体数组struct data/定义日期构造体 int year,month,day;struct sell /*定义销售数据构造*/ int cus; /*顾客代码*/ int num; /*商品编号*/ float sells;/*销售数量*/ char data112;/*日期*/ struct sell * next;*head_s,*pp,*tail_s;/定义头指针操、作指针以及尾指针 str

5、uct customer /*定义销售数据构造*/ int cus; /*顾客代码*/ char name10; /*顾客姓名*/ struct customer * next;*head_c,*,*tail_c;/定义头指针操、作指针以及尾指针void load();/读取文件函数void add();/添加销售信息函数int search_num();/根据商品编号查询商品的销售历史void cal();/计算时间段内各个商品的销售总额int search_name();/根据顾客姓名,查询购买历史void list_name();/显示一切顾客的姓名void main();/主函数int

6、 judge();/主体判别函数int judge_data(char *data1);/细节判别函数,用于判别日期能否合法void download_s();/写入销售信息(顾客代码,销售数量、销售日期)文件void download_c();/导出顾客购买记录void display();/显示如今的商品信息/主函数void main() int choice; struct customer * head;/定义构造指针 head=malloc(sizeof(struct customer);/恳求动态存储空间 head-next=NULL;do printf(*欢迎运用商品销售管理系统

7、!*nn); printf( 1. 导入商品信息n); printf( 2. 显示商品信息n); printf( 3. 输入销售记录记录n); printf( 4. 按编号查寻商品销售历史n); printf( 5. 计算时间段内各个销售总额n); printf( 6. 按顾客姓名查找购买历史n); printf( 7. 显示顾客姓名n); printf( 8. 导出销售信息(顾客代码,销售数量、销售日期)文件n); printf( 9. 导出顾客信息文件n); printf( 0. 退出n); printf(*n); printf(请选择不同功能 输入0-9的数字n 假设输入其它值会提早退出

8、n); scanf(%d,&choice); system(cls); switch(choice) case 1: load(); system(cls); break; case 2: display(); break; case 3: add(); break; case 4: search_num(); break; case 5: cal(); break; case 6: search_name(); break; case 7: list_name(head); break; case 8: download_s(); break; case 9: download_c(); b

9、reak; case 0: printf(nnnn); printf(*谢谢运用*nnnn); break; while(choice0&choicenext=NULL; -next=NULL; system(cls); /*清屏*/ printf(*商品信息*nnn); printf( 商品编号 商品称号 商品价钱 商品产地 库存数量n); while(i10) /输出商品记录 printf(%8d%12s %12.2f%10s%14dn,_producti.num,_,_producti.price, _producti.place,_producti.stora

10、ge); i+; printf(nn查询终了,请按恣意键继续.); getch(); system(cls);void load()/读取文件函数 int i=0,n=0,a,b,j; FILE *fp; /指向文件的指针 do printf(请选择导入商品信息的方法n1:经过键盘输入n2:经过文件导入n); scanf(%d,&a); if(a=2) if(fp=fopen(商品信息.txt,rb)=NULL)/翻开文件 printf(不能翻开文件,请检查文件途径n); /不能翻开 exit(0); /退出*/ printf(*88商品信息88*n); printf(编号 称号 价钱 产地

11、库存数量n); while(!feof(fp) /读入文件 fscanf(fp,%d%s%f%s%d,&_producti.num,_,&_producti.price,_producti.place,&_producti.storage); printf(%-10d%-10s %-10.2f%-12s%-12dn,_producti.num,_,_producti.price,_producti.place,_producti.storage); i+; for(i=0;i10;i+) product1i=_producti; /对备用构造

12、体数组赋值 fclose(fp); /封锁文件 printf(tt数据读入胜利!按恣意键继续.n); if(a=1) if(fp=fopen(商品信息1.txt,w)=NULL)/翻开文件 printf(不能翻开文件,请检查文件途径n); /不能翻开 exit(0); /退出*/ printf(请输入商种类数); scanf(%d,&b); printf(*商品信息*n); printf(编号 称号 价钱 产地 库存数量n); for(j=1;j10000|year12|month31|day30) n=0; if(month=2&day=29) n=0; if(month=4|month=6

13、|month=9|month=11) if(day30) n=0; return n;/判别函数 int judge()/判别商品编号 数量 日期能否正确 int i,j=0,k,temp; for(i=0;inum=_producti.num) j+; x=k=i; temp=_productk.storage; if(_productk.storage-(int)pp-sells)=0) _productk.storage-=(int)pp-sells;/判别计算剩余量 break; if(j=0) return 3;/判别能否存在输入编号的商品 else if(temp-(int)pp-

14、sellssells-(int)pp-sells=1e-6) return 4;/商品量 else if(judge_data(pp-data1)=0) return 0;/判别日期 else return 1;/完全正确/添加销售信息函数void add() int code,i=0,n,m; pp=(struct sell *)malloc(sizeof(struct sell);/恳求动态存储空间并将指针转变为构造类型 =(struct customer *)malloc(sizeof(struct customer);/恳求动态存储空间并将指针转变为构造类型 srand(time(0)

15、; code=rand(); pp-next=NULL; -next=NULL; system(cls); /*清屏*/ printf(请输入销售记录nnn); /*提示输入记录*/ printf(顾客姓名 商品编号 销售数量 销售日期n); printf(-n); scanf(%s%d%f%s,-name,&pp-num,&pp-sells,pp-data1); /*输入记录*/ n=(int)pp-sells; if(nsells); while(1) m=judge();/判别商品编号 数量 日期能否正确 if(m=1) / pp=(struct sell *)malloc(sizeof

16、(struct sell);/恳求动态存储空间并将指针转变为构造类型 / =(struct customer *)malloc(sizeof(struct customer); pp-cus=-cus=code;/随机数 if(head_s=NULL) head_s=pp; else tail_s-next=pp; tail_s=pp; if(head_c=NULL) head_c=; else tail_c-next=; tail_c=; printf(tt销售信息输入胜利!按恣意键继续.n); getch(); system(cls); break; else if(m=2) system

17、(cls); printf(销售数量已大于库存数量,请重新输入:nnn); printf(请输入销售数量nnn); /*提示输入记录*/ printf(销售数量 n); scanf(%f,&pp-sells); /*输入记录*/ continue; else if(m=3) system(cls); printf(无此商品,请重新输入:nnn); printf(请输入销售记录nnn); /*提示输入记录*/ printf( 商品编号 n); scanf(%d,&pp-num); /*输入记录*/ continue; else if(m=4) system(cls); printf(商品数量输入

18、错误,请重新输入商品数量:nnn); printf(请输入销售记录nnn); /*提示输入记录*/ printf(销售数量:n); scanf(%f,&pp-sells); /*输入记录*/ continue; else if(m=0) system(cls); printf(销售日期不合法,请重新输入销售日期:nnn);/*提示输入记录*/ printf(销售日期n); scanf(%s,pp-data1); /*输入记录*/ continue; k+; /根据商品编号查询商品的销售历史search_num() int i,num,k=0,flag=1,n=0; struct sell *

19、ptr; system(cls); printf(请输入商品编号:n); scanf(%d,&num); for(i=0;inext) if(num=ptr-num) if(k=0) printf(商品编号 销售数量 销售总额 销售日期n); printf(-n); k+; printf(%5d%20d%20.2f%15sn,ptr-num,(int)ptr-sells, (int)ptr-sells*_producti.price,ptr-data1); if(k=0) printf(该商品记录为空!按恣意键继续.); getch(); system(cls); return 0; else

20、 printf(nn查询终了,请按恣意键继续.); getch(); system(cls); return 0; /计算时间段内各个商品的销售总额void cal() int i,n=0; struct sell s1,s2,*p=&s1,*q=&s2,*ptr; system(cls); printf(请输入开场日期:); scanf(%s,p-data1); system(cls); do if(judge_data(pp-data1)!=1) printf(输入日期不合法,请重新输入:); scanf(%s,p-data1); system(cls); n=1; else n=0;wh

21、ile(n=1); printf(请输入终了日期:); scanf(%s,q-data1); system(cls);do if(judge_data(q-data1)!=1) printf(输入日期不合法,请重新输入:); scanf(%s,q-data1); system(cls); n=1; else n=0;while(n=1); printf(销售记录如下:tt时间:%s至%sn,p-data1,q-data1); printf(nntt商品编号 销售总额n); printf(tt-nn);for(ptr=head_s;ptr;ptr=ptr-next) for(i=0;inum)

22、break; product1i.storage-=(int)ptr-sells; for(i=0;inext) for(ptr2=head_s;ptr2;ptr2=ptr2-next) if(ptr1-cus=ptr2-cus) break; for(i=0;inum=_producti.num) break; if(strcmp(name,ptr1-name)=0) / if(k=0|k%8=0) printf(顾客姓名 顾客代码 商品编号 购买数量 购买总额 购买日期n); printf(-n); printf(%2s%15d%15d%10d%15.2f%15sn,ptr1-name,p

23、tr1-cus,ptr2-num,(int)ptr2-sells,(int)ptr2-sells)*product1i.price,ptr2-data1); /k+; k=0; if(k=0) printf(不存在此顾客!按恣意键继续.); getch(); system(cls); return 0; else printf(nn查询终了,请按恣意键继续.); getch(); system(cls); return 0; /显示一切顾客的姓名void list_name() int n=1; struct customer * ptr; system(cls); if(head_c!=NU

24、LL)/判别链表能否为空 printf(顾客姓名如下:n);/用来显示一切顾客的姓名 for(ptr=head_c;ptr;ptr=ptr-next) printf(tt%sn,ptr-name); n+; printf(nn顾客姓名查询终了,请按恣意键继续.); getch(); system(cls); else printf(顾客链表为空!请按恣意键继续.); getch(); system(cls); void download_s()/写入销售信息(顾客代码,销售数量、销售日期)文件int i=0; FILE *fp; struct customer *ptr1; struct sell *ptr2; system(cls); if(fp=fopen(销售信息文件.txt,w)=NULL) printf(销售信息文件无法生成!n); exit(0); if(!=NULL) fprintf(fp, 顾客代码 销售数量 购买日期n); for(ptr1=head_c;ptr1;ptr1=ptr1-n

温馨提示

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

评论

0/150

提交评论