c语言图书销售系统源代码_第1页
c语言图书销售系统源代码_第2页
c语言图书销售系统源代码_第3页
c语言图书销售系统源代码_第4页
c语言图书销售系统源代码_第5页
已阅读5页,还剩32页未读 继续免费阅读

付费下载

下载本文档

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

文档简介

1、#include #include #include #include #include #include #define LEN sizeof(struct book) #define VLEN sizeof(struct vip) #define SLEN sizeof(struct sales) struct vip *vhead=NULL;struct vip *v1,*v2; struct sales *shead=NULL;struct sales *s1,*s2; int V,S;/* 结构体定义 */ struct book/*书号 */*书名 */*作者 */*书价 */*

2、书存在本数 */char bnum 12; char bname 41; char author 20;float price;int acount;struct book *next;struct salesfloat count; struct sales *snext;struct vipchar vnum12; char vname41;int level; float persum;float discount; struct vip *vnext;/* 自动读入书库信息 */* 欢迎界面显示 */ /* 增加书本信息 */* 函数声明 */ void loadbook();void

3、 welcome(); void inputbook();void loadvip();void loadsales();void daysales();void monthsales();void yearsales();void search();void search_by_bnum(); void search_by_bname(); void search_by_author(); void buy();void list();void listvip();void listsales();void delet();void delet_by_bnum(); void delet_b

4、y_bname(); void delet_by_author(); void save();void redef();void bover();void buy_by_huiyuan(); void buy_by_feihuiyuan();void exit0();int menu();void print2();void printdelete();/* 自动录入销售信息 */* 日销售额 */* 月销售额 */* 年销售额 */* 查询书数量 */* 通过书号查询 */* 通过书名查询 */* 通过作者查询 */* 购买书籍 */* 列出书库信息 */ /* 列出销售信息 */* 删除书

5、目 */* 通过书号删除 */* 通过书名删除 */* 通过作者删除 */* 保存记录 */* 修改密码 */* 显示已售完的书 */* 会员买书 */* 非会员买书 */*退出 */*主菜单 */* 显示查询菜单 */ /* 显示删除菜单 */struct book *head=NULL,*head2=NULL;/*head和head2分别用于书库的头指针和已购书的头指针 */struct book *p1,*p2,*p3,*p4,*p5,*p6;/*p1、p2、p3 用于操作书库图书, p4、p5、 p6 用于操作已购书 */int save_flag=0;int buy_flag=0;i

6、nt shan_flag=0;int T=0;char mima11=123456; void bookmanage();void salesmanage();/* 图书信息变动标志 */ /*买书时,是否调用过查询功能标志 */* 删书时,是否调用过显示已售完书功能标志 */* 记录导入的书本数 */*初始密码 */* 销售统计 */int main()welcome(); loadbook(); loadsales(); loadvip();/* 主函数 */* 欢迎界面显示 */*自动导入书库信息 */while(1)switch(menu()case 1:system(cls);boo

7、kmanage();break;case 2:system(cls);buy();break;case 3:system(cls);listvip();break;case 4:system(cls);salesmanage();break;case 5:system(cls);break;case 0:system(cls);exit0();break;default:printf(n 选择错误,请按主菜单提示输入您的正确选择 (08)n); printf( 按任意键返回继续 :);rewind(stdin);/* 清空缓冲区 */getch();return 0;/*菜单 */ int m

8、enu() /* 系统清屏 */int choice; system(cls);printf(n*、 t t -l、/,主菜单*nn);printf( printf( printf( printf( printf( printf(1. 图书管理 nn);2. 销售管理 nn);3. 会员管理 nn);4. 销售额统计 nn);5. 说明 nn);0.退出 nnn);printf( 请输入您的选择( 08) :);rewind(stdin); scanf(%d,&choice); return choice;/* 清空缓冲区 */* 返回用户的选择 */void bookmanage() sys

9、tem(cls); int choice1; doprintf(); /* 显示菜单 */Hprintf(* 图书管理*););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)/* 菜单选择 */case 1 : syste

10、m(cls);inputbook(); break;case 2 : system(cls);list(); break ;case 3 : system(cls);search(); break ;case 4 : system(cls);delet(); break ;case 5 : system(cls);save(); break ;case 0 :system(cls); break;while (choice1!=0); printf(n);/* 欢迎界面显示 */欢迎使用图书销售管理系统 *nn); void welcome()system(cls);printf(nntt*

11、* void loadbook()/* 开始导入书库信息 */FILE *fp;struct book *p7;if(fp=fopen(0.txt,r)=NULL) /* 打开文件 */printf(nn文件打开失败或文件不存在 n);printf(nn按回车键继续 :);getchar();return;head=p3=p1=(struct book*)malloc(LEN);/* 开辟一个新单元 */p1-next=NULL;p7=(struct book*)malloc(LEN); /* 作为一个临时存储空间,避免读 取文件最后的回车符 */fscanf(fp,%s %s %s %f %

12、d,&p7-bnum,&p7-bname,&p7-author,&p7-price,&p7-acount);while(!feof(fp)1T+;给 p1*/*p1=*p7;/* 文件没结束就将p7 中的信息读完 */p2=(struct book*)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-acoun t);free(p2);/* 释放多申请的一个单元 */p3-next=NU

13、LL;printf(nnttt%d 项图书信息已经由系统自动载入 .nnttt,T); rewind(stdin);/* 清空缓冲区 */if(fclose(fp)printf( 文件关闭失败 !n);exit(0);void salesmanage()system(cls);int choice4; do printf(); /* 显示菜单 */printf();printf();printf();printf(n);printf(n);printf(n);printf(n);printf(n);printf();printf(t 请选择操作 :); scanf(%d, &choice4);

14、switch (choice4)/* 菜单选择 */*销售统计*功能选项1日销售1=1额2月销售1=1额3年销售1=1额0 :返回主界面case 1 :system(cls);daysales();break;case 2 :system(cls);monthsales();break ;case 3 : system(cls);yearsales(); break ;case 0 : system(cls); break;while (choice4!=0); printf(n);void loadsales()/* 开始导入销售信息 */FILE *vfp;if(vfp=fopen(sal

15、es.txt,r)=NULL) /* 打开文件 */printf(nnttt 销售数据文件打开失败或文件不存在 nn); return;shead=s2=s1=(struct sales*)malloc(VLEN); while(!feof(vfp)S+; fscanf(vfp,%f ,&s2-count); s1=(struct sales*)malloc(VLEN); s2-snext=s1;s2=s1; s1=NULL;s2-snext=NULL;free(s2);printf(nnttt 项销售信息已经由系统自动载入 .nnnnttt,S); rewind(stdin); /* 清空缓

16、冲区 */ if(fclose(vfp)printf( 文件关闭失败 !n); exit(0);void daysales()void monthsales()void yearsales()void listsales()s2=shead;printf(nnttprintf(nn*当前销售信息*n);销售额 nn);while(s2-count!=NULL)printf(%f,s2-count);s2=s2-snext;(s2-snext)=s2=NULL; printf(n);printf( 销售信息列出完毕 ,按回车键返回子菜单 :); rewind(stdin);/* 清空缓冲区 */

17、getchar(); system(cls);void loadvip()/* 开始导入会员信息 */* 打开文件 */FILE *vfp;if(vfp=fopen(1.txt,r)=NULL)printf(nn printf(nn getchar(); return;vip 数据文件打开失败或文件不存在 n); 按回车键继续 :);vhead=v2=v1=(struct vip*)malloc(VLEN); while(!feof(vfp)fscanf(vfp,%s %s %d %f %f,&v2-vnum,&v2-vname,&v2-level,&v2-persum,&v2-di scou

18、nt);v1=(struct vip*)malloc(VLEN);v2-vnext=v1;v2=v1;v1=NULL; v2-vnext=NULL;free(v2);printf(nnttt%d 项会员信息已经由系统自动载入 .nnnnttt 按任意键显示主菜 单:,V);rewind(stdin); /* 清空缓冲区 */ getchar();if(fclose(vfp)printf( 文件关闭失败 !n);exit(0); void listvip()v2=vhead;if(v2=NULL|V=0)/* 文件不存在或书库中没书 */printf(nnnntttt 当前书库没书 !);pri

19、ntf(nntt 按回车键返回 :); rewind(stdin);/* 清空缓冲区 */ getchar();return;elseprintf(nntt*当前书库信息*n);printf(nn 会员号姓名 等级 会员总消费 会员折扣 nn);while(v2-discount!=NULL)printf(%-18s%-10s%-5d%-6.2f %-5fn,v2-vnum,v2-vname,v2-level,v2-persum,v2-discount);v2=v2-vnext; printf(n);printf( 会员信息列出完毕 ,按回车键返回子菜单 :); rewind(stdin);/

20、* 清空缓冲区 */ getchar();system(cls);void buy()system(cls); /* 系统清屏 */int choice1;do printf(); /* 显示菜单 */);printf(*销 售 管 理 *););printf(););printf();printf(功能选项n);printf(1 :会员购买n);printf(2 :非会员购买n);printf(0 :返回主界面n); printf(); printf(t 请选择操作 :); scanf(%d, &choice1);switch (choice1)/* 菜单选择 */case 1 : syst

21、em(cls);buy_by_huiyuan(); break;case 2 : system(cls);buy_by_feihuiyuan(); break ;case 0 : system(cls); break; while (choice1!=0);printf(n);void buy_by_huiyuan()/* 会员买书 */time_t timep;char vipnum6;struct tm *p; time(&timep);p = gmtime(&timep);char bnum11;char ch;int i=0;float sum=0;/* 保存所购买书的总费 */v1=

22、vhead;printf(nnnnnnnnnnnttt 请输入会员号码 :); scanf(%s,vipnum);while(v1!=NULL) if(strcmp(vipnum,v1-vnum)=0) break;else v1=v1-vnext;if(v1=NULL)printf( 对不起,你所输入的会员号不存在 );if(p1=NULL|T=0)/* 文件不存在或书库中没书 */printf(nnnnnnnnnntttt 当前书库没书 !); printf(nntttt按任意键返回 :);rewind(stdin); /* 清空缓冲区 */ getch();return;p5=p4=he

23、ad2=(struct book*)malloc(LEN); p4-next=NULL;system(cls);printf(nntt 收费标准 :一级会员打 9 折 二级会员打 8 折 nnttt 三级会员打 7 折 四级 会员打 6 折 );printf(nn 请输入所需购买的书的书号 ( 图书编号 ):);/* 书号唯一 */ rewind(stdin);/* 清空缓冲区 */gets(bnum);dop1=head;while(p1!=NULL) if(strcmp(p1-bnum,bnum)=0)break;else p1=p1-next; if(p1=NULL)输入书, 是否再次*

24、/ system(cls); printf(nnnnnnnnnnt 没有找到该书信息, 可能书号输入有误? nn);prin tf(nntttY.是 N.否”);rewind(stdin);/* 清空缓冲区 */ ch=getchar(); if(ch=y|ch=Y)system(cls);buy_flag=1;/*防止在此函数中调用时,search。函数执行了清屏search。;/*调用查询,通过其他途径确定书号*/while(1)printf(nnttt 提示:若没有您要找的书 ,可按 0结束 !); printf(nntttt 请重新输入书号 :); rewind(stdin);/* 清

25、空缓冲区 */ gets(bnum);if(strcmp(bnum,0)=0) break;/* 没有需要的书 ,结束输入书号 */ p1=head;while(p1!=NULL)if(strcmp(p1-bnum,bnum)=0) break; else p1=p1-next;if(p1!=NULL) break; system(cls); if(p1!=NULL)if(p1-acount=0)printf(nntttt 该书已售完 !);while(p1!=NULL)if(strcmp(p1-bnum,bnum)=0)/* 有相同书号,循环提前结束 */break;else p1=p1-n

26、ext;*);售价数量:);*/%d!nn);if(p1!=NULL&p1-acount!=0)*p4=*p1;sum=sum+p4-price;p5=(struct book*)malloc(LEN);p4-next=p5;p6=p4;p4=p5;p4-next=NULL;i+;/* 记录买的本数 i,*/p1-acount=p1-acount-1;/* 减去售过的书 (本数 )*/ p4=head2;system(cls);printf(nnt * 当前已选购书状态 printf(nn 书号 书名 作者总费 nn);while(p4-next!=NULL)/* 显示已买过的书 */ pri

27、ntf(%-15s%-25s%-15s %.2f %.2fn,p4-bnum,p4-bname,p4-author,p4-price,p4-acount,sum);p4=p4-next; printf(nntt提示 : 可按 N 结束购书,按任意键继续购书rewind(stdin);/* 清空缓冲区 */ ch=getchar(); system(cls);while(ch!=n&ch!=N);/* 结束购书 */ free(p4);p5-next=NULL; if(head2-next=NULL) printf(nnnnnnnnnntttt 您当前没有购书 else printf(nnnnn

28、nnnnnttt 确认购买这 %d 本书吗 ?n,i); printf(nnttt 按任意键确认,按 N 撤销购书 :);/* 不想购买时 ,亦可撤销 rewind(stdin);/* 清空缓冲区 */ ch=getchar();if(ch=n|ch=N) for(p4=head2;p4!=NULL;p4=p4-next) for(p1=head;p1!=NULL;p1=p1-next) if(strcmp(p1-bnum,p4-bnum)=0)p1-acount=p1-acount+1; /* 书未销售 ,本数加上 */ printf(nntttt 撤销完毕 !);elseprintf(nn

29、ttt 您所购买的书的总费 (打折前 )为 %.2fnn,sum);printf(nnttt 你 的 会 员 等 级 为 %d 级 , 可 以 享 受 %.1f 折.nn,v1-level,(v1-discou nt)*10);printf( 购买书本的折后价为 %.2f.nn,(v1-discount)*sum);save_flag=1;/* 书库信息变动标志 */printf(%d.%d.%dn, (1900+p-tm_year), (1+p-tm_mon), p-tm_mday);rewind(stdin);/* 清空缓冲区 */printf(nnttt按回车键返回主菜单 );getch

30、ar();void buy_by_feihuiyuan()/* 非会员买书 */char bnum11;char ch;int i=0;float sum=0;/*保存所购买书的总费 */p1=head;if(p1=NULL|T=0)/*文件不存在或书库中没书 */printf(nnnnnnnnnntttt 当前书库没书 !); printf(nntttt按任意键返回 :);rewind(stdin);/*清空缓冲区 */getch();return;p5=p4=head2=(struct book*)malloc(LEN);p4-next=NULL;doprintf(nn请输入所需购买的书的

31、书号(图书编号 ):);/* 书号唯一 */rewind(stdin);/* 清空缓冲区 */gets(bnum);p1=head;while(p1!=NULL)if(strcmp(p1-bnum,bnum)=0)if(p1=NULL), 是否再次*/ system(cls); printf(nnnnnnnnnnt 没有找到该书信息 , 可能书号输入有误 输入书号? nn);prin tf(nntttY.是N.否”);rewind(stdin);/* 清空缓冲区 */ ch=getchar(); if(ch=y|ch=Y) system(cls);buy_flag=1;/*防止在此函数中调用时

32、,search。函数执行了清屏search。;/*调用查询,通过其他途径确定书号*/while(1)printf(nnttt 提示:若没有您要找的书,可按 0结束 !);printf(nntttt 请重新输入书号 :);rewind(stdin);/* 清空缓冲区 */ gets(bnum);if(strcmp(bnum,0)=0) break;/* 没有需要的书 ,结束输入书号 */ p1=head;while(p1!=NULL)if(strcmp(p1-bnum,bnum)=0) break; else p1=p1-next;if(p1!=NULL) break; system(cls);

33、if(p1!=NULL)if(p1-acount=0) printf(nntttt 该书已售完 !);while(p1!=NULL) if(strcmp(p1-bnum,bnum)=0)/* 有相同书号,循环提前结束 */ break;else p1=p1-next;if(p1!=NULL&p1-acount!=0)*p4=*p1;sum=sum+p4-price;p5=(struct book*)malloc(LEN);p4-next=p5;p6=p4;p4=p5; p4-next=NULL; i+;/* 记录买的本数 i,*/ p1-acount=p1-acount-1;/* 减去售过的书

34、 (本数 )*/p4=head2;system(cls);printf(nnt*当前已选购书状态 *);printf(nn 书号 书名 作者 总费 nn);while(p4-next!=NULL)/* 显示已买过的书 */%dprintf(%-15s%-25s%-15s %.2f%.2fn,p4-bnum,p4-bname,p4-author,p4-price,p4-acount,sum);p4=p4-next;printf(nntt提示 : 可按 N 结束购书,按任意键继续购书 :);rewind(stdin);/* 清空缓冲区 */ ch=getchar();system(cls);whi

35、le(ch!=n&ch!=N);/* 结束购书 */free(p4);p5-next=NULL;if(head2-next=NULL) printf(nnnnnnnnnntttt 您当前没有购书 !nn);else printf(nnnnnnnnnnttt 确认购买这 %d 本书吗 ?n,i); printf(nnttt 按任意键确认,按 N 撤销购书 :);/* 不想购买时 ,亦可撤销 */ rewind(stdin);/* 清空缓冲区 */ ch=getchar();if(ch=n|ch=N)for(p4=head2;p4!=NULL;p4=p4-next)for(p1=head;p1!=

36、NULL;p1=p1-next)if(strcmp(p1-bnum,p4-bnum)=0)p1-acount=p1-acount+1;/* 书未销售 ,本数加上 */ printf(nntttt 撤销完毕 !); elseprintf(nnttt 您所购买的书的总费为 %.2fnn,sum); save_flag=1;/* 书库信息变动标志 */rewind(stdin);/* 清空缓冲区 */ printf(nnttt 按回车键返回主菜单 ); getchar();void search() /* 查询书库信息 */int choice;/* 文件不存在或书库中没书 */p1=head;if

37、(p1=NULL|T=0)printf(nnnntttt 当前书库没书 !);printf(nntt rewind(stdin); getch(); system(cls); return;while(1) printf(n printf( printf( printf( printf( printf(nn rewind(stdin);按任意键返回 :);/* 清空缓冲区 */*1.通过书号查找2.通过书名查找3.通过作者查找0.退出图书查询 请选择一种查询方式查询方式 *nn);nn);nn);nn);nn);(03):);/* 清空缓冲区 */scanf(%d,&choice);while

38、(choice3)system(cls);print2(); /* 调用显示查询方式菜单 */ printf(nttt 输入错误 !nn);printf(ttt 请重新输入 :);rewind(stdin); /* 清空缓冲区 */ scanf(%d,&choice);switch(choice)case 1:system(cls);search_by_bnum();break; case 2:system(cls);search_by_bname();break;case 3:system(cls);search_by_author();break;case 0:system(cls);re

39、turn;printf(ntttt 按回车键继续 :);rewind(stdin); getchar(); if(buy_flag=1) 以便看着列表输入书号 */* 清空缓冲区 */* 购书调用此函数时, 要提前结束,不能执行清屏,break;system(cls);void print2()/* 查询方式菜单 */printf(n*查询方式*nn);printf( printf( printf( printf(1. 通过书号查找 nn);2. 通过书名查找 nn);3. 通过作者查找 nn);0.退出图书查询 nn);void search_by_bnum()/* 通过书号查询 */cha

40、r bnum 11; printf(nnnnnnnnnntttt 请输入书号 :); rewind(stdin);/* 清空缓冲区 */scanf(%s,bnum);p1=head; while(p1!=NULL) if(strcmp(p1-bnum,bnum)=0) /* 有相同书号,循环提前结束 */ break;else p1=p1-next; if(p1=NULL) printf(nnt对不起 !该书库没有您要找的书 !nn);elsesystem(cls);printf(nn*当前查找状态显示*nn);printf(nn 书号 书名作者 售价 数量 nn);printf(%-15s%

41、-25s%-15s%.2f %dn,p1-bnum,p1-bname,p1-author,p1-price,p1-acount); /* 通过书名查询 */ void search_by_bname()char bname 40; printf(nnnnnnnnnntttt 请输入书名 :); rewind(stdin);/* 清空缓冲区 */ scanf(%s,bname);p1=head;while(p1!=NULL) if(strcmp(p1-bname,bname)=0) /* 有相同书名,循环提前结束 */ break;else p1=p1-next;if(p1=NULL) prin

42、tf(nnt对不起 ! 该书库没有您要找的书 !nn);elsep2=p1;/* 同种书名的书 */ system(cls);printf(nn*nn);printf(nn 书号书名当前查找状态显作者 售价 数量 nn);while(p2!=NULL)if(strcmp(p1-bname,p2-bname)=0)printf(%-15s%-25s%-15s%.2f %dn,p2-bnum,p2-bname,p2-author,p2-price,p2-acount);p2=p2-next; /* 通过作者查询 */ void search_by_author()char author 20;pr

43、intf(nnnnnnnnnntttt 请输入作者 :); rewind(stdin);/* 清空缓冲区 */scanf(%s,author);p1=head;while(p1!=NULL) if(strcmp(p1-author,author)=0)/* 有相同作者,循环提前结束 */ break;else p1=p1-next;对不起 !该书库没有您要找的书 !nn);if(p1=NULL) printf(nnt elsep2=p1;/* 同一个作者 */system(cls);printf(nn*nn);printf(nn 书号*书名当前查找状态显示作者 售价 数量 nn);while(

44、p2!=NULL)if(strcmp(p1-author,p2-author)=0) printf(%-15s%-25s%-15s%.2f%dn,p2-bnum,p2-bname,p2-author,p2-price,p2-acount);p2=p2-next; /* 显示已售完的书 */ void bover() struct book *p9;int print_flag=0; p9=head; while(p9!=NULL) if(p9-acount=0)if(print_flag=0) printf(nntttt 当前已售完的图书 nn);%-6.2fprintf(%-15s%-25s

45、%-15s %-5dn,p9-bnum,p9-bname,p9-author,p9-price,p9-acount);print_flag=1;/* 当前已售完的图书 与 当前书库没有已售完的图书 只能显示一个 */ p9=p9-next;if(print_flag=0) printf(nnnnnnnnnntttt 当前书库没有已售完的图书 );printf(nntttt 按回车键继续 :); rewind(stdin);/* 清空缓冲区 */* 显示删除菜单 */void printdelete()printf(n*删除方式*nn);printf(1.通过书号删除 nn);printf( printf( printf(2.通过书名删除 nn);3.通过作者删除 nn);0.退出图书删除 nn);/* 删除图书信息 */void delet()char password10,ch;int n=0,choice;int mima_flag=0;/* 密码是否正确标志 */ printf(

温馨提示

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

评论

0/150

提交评论