收藏 分销(赏)

c语言图书销售系统(源代码).docx

上传人:pc****0 文档编号:8842476 上传时间:2025-03-04 格式:DOCX 页数:33 大小:23.16KB
下载 相关 举报
c语言图书销售系统(源代码).docx_第1页
第1页 / 共33页
c语言图书销售系统(源代码).docx_第2页
第2页 / 共33页
点击查看更多>>
资源描述
#include <stdio.h> #include <string.h> #include <malloc.h> #include <stdlib.h> #include <time.h> #include <conio.h> #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 { char bnum [12]; /*书号*/ char bname [41]; /*书名*/ char author [20]; /*作者*/ float price; /*书价*/ int acount; /*书存在本数*/ struct book *next; }; struct sales { float count; struct sales *snext; }; struct vip { char vnum[12]; char vname[41]; int level; float persum; float discount; struct vip *vnext; }; /*函数声明*/ void loadbook(); /*自动读入书库信息*/ void 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_by_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(); /*显示删除菜单*/ 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; /*买书时,是否调用过查询功能标志*/ int shan_flag=0; /*删书时,是否调用过显示已售完书功能标志*/ int T=0; /*记录导入的书本数*/ char mima[11]="123456"; /*初始密码*/ void bookmanage(); void salesmanage(); /*销售统计*/ int main() /*主函数*/ { welcome(); /*欢迎界面显示*/ loadbook(); loadsales(); loadvip(); /*自动导入书库信息*/ while(1) { switch(menu()) { case 1:system("cls");bookmanage();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选择错误,请按主菜单提示输入您的正确选择(0~8)\n"); printf("按任意键返回继续:"); rewind(stdin);/*清空缓冲区*/ getch(); } } } return 0; } /*菜单*/ int menu() { int choice; 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); return choice; /*返回用户的选择*/ } void bookmanage() { system("cls"); int choice1; 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) /*菜单选择*/ { case 1 : system("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"); } void welcome() /*欢迎界面显示*/ { system("cls"); printf("\n\n\t\t*************欢迎使用图书销售管理系统*************\n\n"); } void loadbook() /*开始导入书库信息*/ { FILE *fp; struct book *p7; if((fp=fopen("0.txt","r"))==NULL) /*打开文件*/ { printf("\n\n 文件打开失败或文件不存在\n"); printf("\n\n 按回车键继续:"); getchar(); return; } head=p3=p1=(struct book*)malloc(LEN); /*开辟一个新单元*/ p1->next=NULL; p7=(struct book*)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=(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->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); } } void salesmanage() { system("cls"); int choice4; 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) /*菜单选择*/ { 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("sales.txt","r"))==NULL) /*打开文件*/ { printf("\n\n\t\t\t销售数据文件打开失败或文件不存在\n\n"); 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("\n\n\t\t\t项销售信息已经由系统自动载入.\n\n\n\n\t\t\t",S); rewind(stdin); /*清空缓冲区*/ if(fclose(vfp)) { printf("文件关闭失败!\n"); exit(0); } } void daysales() { } void monthsales() { } void yearsales() { } void listsales() { 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"); } void loadvip() /*开始导入会员信息*/ { FILE *vfp; if((vfp=fopen("1.txt","r"))==NULL) /*打开文件*/ { printf("\n\n vip数据文件打开失败或文件不存在\n"); printf("\n\n 按回车键继续:"); getchar(); return; } vhead=v2=v1=(struct vip*)malloc(VLEN); while(!feof(vfp)) { V++; fscanf(vfp,"%s %s %d %f %f",&v2->vnum,&v2->vname,&v2->level,&v2->persum,&v2->discount); v1=(struct vip*)malloc(VLEN); v2->vnext=v1; v2=v1; } v1=NULL; v2->vnext=NULL; free(v2); printf("\n\n\t\t\t%d项会员信息已经由系统自动载入.\n\n\n\n\t\t\t按任意键显示主菜单:",V); rewind(stdin); /*清空缓冲区*/ getchar(); if(fclose(vfp)) { printf("文件关闭失败!\n"); exit(0); } } void listvip() { v2=vhead; if(v2==NULL||V==0)/*文件不存在或书库中没书*/ { printf("\n\n\n\n\t\t\t\t当前书库没书!!!"); printf("\n\n\t\t 按回车键返回:"); rewind(stdin);/*清空缓冲区*/ getchar(); return; } else { printf("\n\n\t\t *************当前书库信息*************\n"); printf("\n\n会员号 姓名 等级 会员总消费 会员折扣\n\n"); while(v2->discount!=NULL) { printf("%-18s%-10s%-5d %-6.2f %-5f\n",v2->vnum,v2->vname,v2->level,v2->persum,v2->discount); v2=v2->vnext; } printf("\n"); } printf("会员信息列出完毕,按回车键返回子菜单:"); rewind(stdin);/*清空缓冲区*/ 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 : system("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 vipnum[6]; struct tm *p; time(&timep); p = gmtime(&timep); char bnum[11]; char ch; int i=0; float sum=0; /*保存所购买书的总费*/ v1=vhead; printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t请输入会员号码:"); 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("\n\n\n\n\n\n\n\n\n\n\t\t\t\t当前书库没书!!!"); printf("\n\n\t\t\t\t 按任意键返回:"); rewind(stdin); /*清空缓冲区*/ getch(); return; } p5=p4=head2=(struct book*)malloc(LEN); p4->next=NULL; system("cls"); printf("\n\n\t\t收费标准:一级会员打9折 二级会员打8折\n\n\t\t\t三级会员打7折 四级会员打6折 "); do{ printf("\n\n 请输入所需购买的书的书号(图书编号):");/*书号唯一*/ rewind(stdin);/*清空缓冲区*/ gets(bnum); p1=head; while(p1!=NULL) { if(strcmp(p1->bnum,bnum)==0) break; else p1=p1->next; } if(p1==NULL) { system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t 没有找到该书信息,可能书号输入有误,是否再次输入书号?\n\n"); printf("\n\n\t\t\t Y.是 N.否"); rewind(stdin);/*清空缓冲区*/ ch=getchar(); if(ch=='y'||ch=='Y') { system("cls"); buy_flag=1;/*防止在此函数中调用时,search()函数执行了清屏*/ search();/*调用查询,通过其他途径确定书号*/ } while(1) { printf("\n\n\t\t\t提示:若没有您要找的书,可按0结束!!!"); printf("\n\n\t\t\t\t请重新输入书号:"); 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"); } } if(p1!=NULL) if(p1->acount==0) printf("\n\n\t\t\t\t该书已售完!!!"); 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;/*减去售过的书(本数)*/ p4=head2;system("cls"); printf("\n\n\t ***********当前已选购书状态***********"); printf("\n\n书号 书名 作者 售价 数量 总费\n\n"); while(p4->next!=NULL)/*显示已买过的书*/ { printf("%-15s%-25s%-15s %.2f %d %.2f\n",p4->bnum,p4->bname,p4->author,p4->price,p4->acount,sum); p4=p4->next; } } printf("\n\n\t\t 提示:可按N结束购书,按任意键继续购书:"); rewind(stdin);/*清空缓冲区*/ ch=getchar(); system("cls"); }while(ch!='n'&&ch!='N');/*结束购书*/ free(p4); p5->next=NULL; if(head2->next==NULL) printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t您当前没有购书!!!\n\n"); else { printf("\n\n\n\n\n\n\n\n\n\n\t\t\t 确认购买这%d本书吗???\n",i); printf("\n\n\t\t\t 按任意键确认,按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("\n\n\t\t\t\t 撤销完毕!!!!"); } else { printf("\n\n\t\t\t您所购买的书的总费(打折前)为%.2f\n\n",sum); printf("\n\n\t\t\t你的会员等级为%d级,可以享受%.1f折.\n\n",v1->level,(v1->discount)*10); printf("购买书本的折后价为%.2f.\n\n",(v1->discount)*sum); save_flag=1;/*书库信息变动标志*/ } printf("%d.%d.%d\n", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday); } rewind(stdin);/*清空缓冲区*/ printf("\n\n\t\t\t 按回车键返回主菜单"); getchar(); } void buy_by_feihuiyuan() /*非会员买书*/ { char bnum[11]; char ch; int i=0; float sum=0; /*保存所购买书的总费*/ p1=head; if(p1==NULL||T==0) /*文件不存在或书库中没书*/ { printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t当前书库没书!!!"); printf("\n\n\t\t\t\t 按任意键返回:"); rewind(stdin); /*清空缓冲区*/ getch(); return; } p5=p4=head2=(struct book*)malloc(LEN); p4->next=NULL; do{ printf("\n\n 请输入所需购买的书的书号(图书编号):");/*书号唯一*/ rewind(stdin);/*清空缓冲区*/ gets(bnum); p1=head; while(p1!=NULL) { if(strcmp(p1->bnum,bnum)==0) break; else p1=p1->next;
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服