您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 市场营销 > c语言图书销售系统(源代码)
#includestdio.h#includestring.h#includemalloc.h#includestdlib.h#includetime.h#includeconio.h#defineLENsizeof(structbook)#defineVLENsizeof(structvip)#defineSLENsizeof(structsales)structvip*vhead=NULL;structvip*v1,*v2;structsales*shead=NULL;structsales*s1,*s2;intV,S;/*结构体定义*/structbook{charbnum[12];/*书号*/charbname[41];/*书名*/charauthor[20];/*作者*/floatprice;/*书价*/intacount;/*书存在本数*/structbook*next;};structsales{floatcount;structsales*snext;};structvip{charvnum[12];charvname[41];intlevel;floatpersum;floatdiscount;structvip*vnext;};/*函数声明*/voidloadbook();/*自动读入书库信息*/voidwelcome();/*欢迎界面显示*/voidinputbook();/*增加书本信息*/voidloadvip();voidloadsales();/*自动录入销售信息*/voiddaysales();/*日销售额*/voidmonthsales();/*月销售额*/voidyearsales();/*年销售额*/voidsearch();/*查询书数量*/voidsearch_by_bnum();/*通过书号查询*/voidsearch_by_bname();/*通过书名查询*/voidsearch_by_author();/*通过作者查询*/voidbuy();/*购买书籍*/voidlist();/*列出书库信息*/voidlistvip();voidlistsales();/*列出销售信息*/voiddelet();/*删除书目*/voiddelet_by_bnum();/*通过书号删除*/voiddelet_by_bname();/*通过书名删除*/voiddelet_by_author();/*通过作者删除*/voidsave();/*保存记录*/voidredef();/*修改密码*/voidbover();/*显示已售完的书*/voidbuy_by_huiyuan();/*会员买书*/voidbuy_by_feihuiyuan();/*非会员买书*/voidexit0();/*退出*/intmenu();/*主菜单*/voidprint2();/*显示查询菜单*/voidprintdelete();/*显示删除菜单*/structbook*head=NULL,*head2=NULL;/*head和head2分别用于书库的头指针和已购书的头指针*/structbook*p1,*p2,*p3,*p4,*p5,*p6;/*p1、p2、p3用于操作书库图书,p4、p5、p6用于操作已购书*/intsave_flag=0;/*图书信息变动标志*/intbuy_flag=0;/*买书时,是否调用过查询功能标志*/intshan_flag=0;/*删书时,是否调用过显示已售完书功能标志*/intT=0;/*记录导入的书本数*/charmima[11]=123456;/*初始密码*/voidbookmanage();voidsalesmanage();/*销售统计*/intmain()/*主函数*/{welcome();/*欢迎界面显示*/loadbook();loadsales();loadvip();/*自动导入书库信息*/while(1){switch(menu()){case1:system(cls);bookmanage();break;case2:system(cls);buy();break;case3:system(cls);listvip();break;case4:system(cls);;salesmanage();break;case5:system(cls);;break;case0:system(cls);exit0();break;default:{printf(\n选择错误,请按主菜单提示输入您的正确选择(0~8)\n);printf(按任意键返回继续:);rewind(stdin);/*清空缓冲区*/getch();}}}return0;}/*菜单*/intmenu(){intchoice;system(cls);/*系统清屏*/printf(\n*************************主菜单*************************\n\n);printf(1.图书管理\n\n);printf(2.销售管理\n\n);printf(3.会员管理\n\n);printf(4.销售额统计\n\n);printf(5.说明\n\n);printf(0.退出\n\n\n);printf(请输入您的选择(0~8):);rewind(stdin);/*清空缓冲区*/scanf(%d,&choice);returnchoice;/*返回用户的选择*/}voidbookmanage(){system(cls);intchoice1;do{printf();/*显示菜单*/printf(*************图书管理*************);printf();printf();printf(功能选项:\n);printf(1:图书信息录入\n);printf(2:图书信息浏览\n);printf(3:图书信息查询\n);printf(4:图书信息删除\n);printf(5:图书信息保存\n);printf(0:返回主界面\n);printf();printf(\t请选择操作:);scanf(%d,&choice1);switch(choice1)/*菜单选择*/{case1:system(cls);inputbook();break;case2:system(cls);list();break;case3:system(cls);search();break;case4:system(cls);delet();break;case5:system(cls);save();break;case0:system(cls);break;}}while(choice1!=0);printf(\n);}voidwelcome()/*欢迎界面显示*/{system(cls);printf(\n\n\t\t*************欢迎使用图书销售管理系统*************\n\n);}voidloadbook()/*开始导入书库信息*/{FILE*fp;structbook*p7;if((fp=fopen(0.txt,r))==NULL)/*打开文件*/{printf(\n\n文件打开失败或文件不存在\n);printf(\n\n按回车键继续:);getchar();return;}head=p3=p1=(structbook*)malloc(LEN);/*开辟一个新单元*/p1-next=NULL;p7=(structbook*)malloc(LEN);/*作为一个临时存储空间,避免读取文件最后的回车符*/fscanf(fp,%s%s%s%f%d,&p7-bnum,&p7-bname,&p7-author,&p7-price,&p7-acount);while(!feof(fp)){T++;*p1=*p7;/*文件没结束就将p7中的信息给p1*/p2=(structbook*)malloc(LEN);/*继续开辟一个新单元,直到文件读完*/p1-next=p2;p3=p1;p1=p2;p1-next=NULL;fscanf(fp,%s%s%s%f%d,&p7-bnum,&p7-bname,&p7-author,&p7-price,&p7-acount);}free(p2);/*释放多申请的一个单元*/p3-next=NULL;printf(\n\n\t\t\t%d项图书信息已经由系统自动载入.\n\n\t\t\t,T);rewind(stdin);/*清空缓冲区*/if(fclose(fp)){printf(文件关闭失败!\n);exit(0);}}voidsalesmanage(){system(cls);intchoice4;do{printf();/*显示菜单*/printf(*************销售统计*************);printf();printf();printf(功能选项:\n);printf(1:日销售额\n);printf(2:月销售额\n);printf(3:年销售额\n);printf(0:返回主界面\n);printf();printf(\t请选择操作:);scanf(%d,&choice4);switch(choice4)/*菜单选择*/{case1:system(cls);daysales();break;case2:system(cls);monthsales();break;case3:system(cls);yearsales();break;case0:system(cls);break;}}while(choice4!=0);printf(\n);}voidloadsales()/*开始导入销售信息*/{FILE*vfp;if((vfp=fopen(sales.txt,r))==NULL)/*打开文件*/{printf(\n\n\t\t\t销售数据文件打开失败或文件不存在\n\n);return;}shead=s2=s1=(structsales*)malloc(VLEN);while(!feof(vfp)){S++;fscanf(vfp,%f,&s2-count);s1=(structsales*)malloc(VLEN);s2-snext=s1;s2=s1;}s1=NULL;s2-snext=NULL;free(s2);printf(\n\n\t\t\t项销售信息已经由系统自动载入.\n\n\n\n\t\t\t,S);rewind(stdin);/*清空缓冲区*/if(fclose(vfp)){printf(文件关闭失败!\n);exit(0);}}voiddaysales(){}voidmonthsales(){}voidyearsales(){}voidlistsales(){s2=shead;{printf(\n\n\t\t*************当前销售信息*************\n);printf(\n\n销售额\n\n);while(s2-count!=NULL){printf(%f,s2-count);s2=s2-snext;}(s2-snext)=s2=NULL;printf(\n);}printf(销售信息列出完毕,按回车键返回子菜单:);rewind(stdin);/*清空缓冲区*/getchar();system(cls);}voidloadvip()/*开始导入会员信息*/{FILE*vfp;if((vfp=fopen(1.txt,r))==NULL)/*打开文件*/{printf(\n\nvip数据文件打开失败或文件不存在\n);printf(\n\n按回车键继续:);getchar();return;}vhead=v2=v1=(structvip*)malloc(VLEN);while
本文标题:c语言图书销售系统(源代码)
链接地址:https://www.777doc.com/doc-1698761 .html