图书管理系统程序代码.pdf
include stdio.hinclude include 欢迎使用君宁图书管理系统 name,name);strcpy(p zuozhe,zuozhe);strcpy(p leibie,leibie);strcpy(p-pub_time,pub_time);strcpy(p price,price);strcpy(p-condition,condition);p-next=NULL;if(head=NULL)head=p;elsetail next=p;tail=p;printf(”请输入图书编号:);gets(num);printf(”图书源信息已建立链条!n);return head;/创建已借阅图书源信息链表struct borrow*borrow_creat(struct booklist head)struct booklist p;struct borrow*borrow_head,*p1,*tail;borrow_head=p1=tail=NULL;for(p=head;p!=NULL;p=p-next)p1=(struct borrow*)malloc(sizeof(struct borrow));if(strcmp(p-condition,”借出)=0)printf(”创建借出信息:n);strcpy(p1-borbook_num,p-num);strcpy(p1 borbook_name,p-name);getchar();printf(借阅编号为s 的图书的借阅信息:n”,p num);printf(请输入应归还时间:”);gets(p1 return_time);printf(”请输入学生学号:”);gets(p1 stu_num);printf(”请输入学生姓名:);gets(p1 stu_name);printf(n);p1 next=NULL;if(borrow_head=NULL)borrow_head=p1;elsetail next=p1;tail=p1;printf(”成功创建已借出信息链表!nn”);getchar();return borrow_head;/保存已借阅图书信息到文件 borrowlist。txtvoid borstore(struct borrow*borrow_head)FILE*fp;struct borrow p;if((fp=fopen(borrowlist。txt”,”w”)=NULL)printf(”File open error!n);exit(0);p=borrow_head;while(p!=NULL)fprintf(fp,”16s26s16s16s16sn”,p-borbook_num,p borbook_name,p return_time,p-stu_num,p-stu_name);p=p-next;fclose(fp);printf(文件成功保存到 borrowlist.txt 中!n);getchar();/从文件提取信息创建已借阅图书源信息链表struct borrow borload(void)struct borrow p,*tail,*head;FILE*fp;head=p=tail=NULL;if(fp=fopen(borrowlist.txt”,”r)=NULL)printf(”文件 borrowlist。txt 打开失败!n”);getchar();exit(0);while(!feof(fp)p=(struct borrow)malloc(sizeof(struct borrow));fscanf(fp,%16s26s%16s16s%16sn”,p borbook_num,p-borbook_name,p return_time,p-stu_num,p stu_name);if(head=NULL)head=p;elsetail next=p;tail=p;tail-next=NULL;fclose(fp);printf(”已成功从文件 borrowlist.txt 提取信息创建已借阅图书源信息!n);return head;/录入预借图书信息并将信息存入文件 prebor_stulist.txtint pre_creat(struct booklist*head)struct booklistb;struct prebor_stu*p;char a10,c15;int n,x=1,flag=1;FILE fp;b=head;p=(struct prebor_stu*)malloc(sizeof(struct prebor_stu);printf(进入预借图书!(按回车键继续、)n);getchar();while(x)printf(”请输入要预借阅的图书编号:);gets(a);while(strcmp(b-num,a)!=0)&b next!=NULL)b=b-next;if(strcmp(b num,a)!=0)printf(”没有找到编号为s 的图书!n,a);printf(输入0 结束录入!(输入其他数字继续录入。.)nn);printf(请选择功能:);scanf(”%d,&n);getchar();if(n=0)x=0;getchar();elseprintf(”请输入学号:”);gets(c);strcpy(p-prebook_num,a);strcpy(p-prestu_num,c);if(fp=fopen(prebor_stulist。txt,a+”)=NULL)printf(”File open error!n);exit(0);fprintf(fp,%16s%16sn,p prebook_num,p-prestu_num);fclose(fp);flag=2;printf(输入-0 结束录入!(输入其他数字继续录入.。)nn);printf(请选择功能:”);scanf(”%d”,n);getchar();if(n=0)x=0;getchar();return flag;/重新保存修改后的预借阅信息到文件 prebor_stulist.txt(全部覆盖)void prestore(struct prebor_stu*pre_head)struct prebor_stu p;FILE*fp;p=pre_head;if(fp=fopen(prebor_stulist.txt”,”w)=NULL)printf(File open error!n);exit(0);while(p!=NULL)fprintf(fp,16s16sn”,p prebook_num,p prestu_num);p=p next;fclose(fp);printf(”文件成功保存到 prebor_stulist。txt 中!n”);getchar();/从文件 prebor_stulist。txt 创建预借阅图书信息链表struct prebor_stu*prebor_creat(void)struct prebor_stu*p,tail,*head;FILE fp;head=p=tail=NULL;if(fp=fopen(prebor_stulist。txt,r))=NULL)printf(文件 prebor_stulist。txt 打开失败!n”);getchar();while(!feof(fp))p=(struct prebor_stu*)malloc(sizeof(struct prebor_stu));fscanf(fp,”%16s%16sn”,p prebook_num,p-prestu_num);if(head=NULL)head=p;elsetail next=p;tail=p;tail-next=NULL;fclose(fp);printf(已从文件 prebor_stulist。txt 成功读取并建立预借阅图书信息!n”);getchar();return head;/*2-保存链表中的图书信息到文件booklist.txt*/void store(struct booklist head)FILE fp;struct booklist p;if(fp=fopen(”booklist。txt,w”))=NULL)printf(”File open error!n);exit(0);p=head;while(p!=NULL)fprintf(fp,”%16s%26s16s%16s16s16s16sn,p-num,p-name,p zuozhe,p leibie,p-pub_time,p price,p condition);p=p-next;fclose(fp);printf(”文件成功保存到 booklist.txt 中!n”);getchar();/输入单个图书源数据struct booklist*scanf1_(void)struct booklist*p;p=SIZE;printf(请输入图书编号:);gets(p-num);printf(请输入书名:”);gets(p name);printf(”请输入作者:);gets(p zuozhe);printf(”请输入类别:”);gets(p leibie);printf(请输入出版时间:);gets(p-pub_time);printf(”请输入价格:”);gets(p-price);printf(请输入借阅情况:);gets(p condition);return p;/输出单个图书的数据void printf1_(struct booklist*p)printf(编号:);puts(p-num);printf(书名:”);puts(p-name);printf(作者:”);puts(p-zuozhe);printf(”类别:);puts(p leibie);printf(出版时间:);puts(p-pub_time);printf(”价格:”);puts(p price);printf(”借阅情况:”);puts(p condition);/输出单个借出图书的部分数据void printfb1_(struct borrow*p)printf(应归还时间:”);puts(p return_time);printf(借阅学生学号:);puts(p stu_num);printf(”借阅学生姓名:”);puts(p stu_name);/输出单个借出图书的数据void printfb_(struct borrow*p)printf(图书编号:);puts(p-borbook_num);printf(”书名:”);puts(p borbook_name);printf(”应归还时间:”);puts(p-return_time);printf(”借阅学生学号:);puts(p-stu_num);printf(”借阅学生姓名:);puts(p stu_name);/输出单个被预借出图书的部分数据void printfp1_(struct prebor_stu p)printf(”预借图书的学生学号:”);puts(p prestu_num);/输出单个被预借出图书的数据void printfp_(struct prebor_stu*p)printf(”图书编号:”);puts(p-prebook_num);printf(”预借阅图书的学生学号:”);puts(p-prestu_num);/3-输出链表中的图书信息/void printf_(struct booklist head,struct borrow borrow_head,struct prebor_stu*pre_head)struct booklist p;struct borrow*b;struct prebor_stu pre;int x=1,n;p=head;b=borrow_head;pre=pre_head;while(x=1)system(”cls);printf(*欢迎使用君宁图书信息输出系统*n);printf(”0-退出*n);printf(”*1-输出图书源信息*n”);printf(”2-输出借出图书信息*n”);printf(*3-输出预借借图书信息n);printf(”*祝您使用愉快*n”);printf(”请选择功能:);scanf(d”,&n);getchar();switch(n)case 0:x=0;break;case 1:if(head!=NULL)printf(”图书源信息如下:n”);doprintf1_(p);printf(”nn”);p=p next;while(p!=NULL);getchar();break;case 2:if(borrow_head=NULL)printf(没有借出图书信息(按回车键继续、)!n);getchar();break;elseprintf(借出图书信息如下:n”);doprintfb_(b);printf(nn);b=b next;while(b!=NULL);printf(按回车键继续、n);getchar();break;case 3:if(pre_head=NULL)printf(”没有预借图书信息(按回车键继续、)!n);getchar();getchar();break;elseprintf(”预借借图书信息如下:n”);doprintfp_(pre);printf(”nn”);pre=pre next;while(pre!=NULL);printf(”按回车键继续、n);getchar();break;default:printf(”输入错误(按回车键继续、)!n”);getchar();break;/11-从文件读入图书信息struct booklist*load(void)struct booklist*p,tail,*head;FILE*fp;head=p=tail=NULL;if((fp=fopen(booklist。txt”,”r”))=NULL)printf(文件 booklist。txt 打开失败!n);getchar();exit(0);while(!feof(fp)p=SIZE;fscanf(fp,”%16s%26s%16s16s%16s%16s16sn,p num,zuozhe,p-leibie,p-pub_time,p-price,p condition);if(head=NULL)head=p;elsetail next=p;tail=p;tail-next=NULL;fclose(fp);printf(已成功读取文件 booklist.txt,建立源图书信息链表!n”);return head;/4-按编号排序并输出struct booklist num_paixu(struct booklist head)struct booklist p,*p1,*tail;p1=NULL;tail=SIZE;for(p=head;p-next!=NULL;p=p-next)p-name,p-for(p1=pnext;p1!=NULL;p1=p1-next)if(strcmp(p num,p1-num)0)exchange(tail,p1);exchange(p1,p);exchange(p,tail);printf(”图书已按编号排序成功,具体信息如下:n);for(p=head;p!=NULL;p=p next)printf1_(p);printf(n”);return head;/3-按价格排序struct booklist*price_paixu(struct booklist*head)struct booklist p,p1,*tail;p1=NULL;tail=SIZE;for(p=head;p-next!=NULL;p=p next)for(p1=p-next;p1!=NULL;p1=p1next)if(strcmp(p-price,p1-price)0)exchange(tail,p1);exchange(p1,p);exchange(p,tail);printf(”图书已按价格排序成功,具体信息如下:n);for(p=head;p!=NULL;p=p next)printf1_(p);printf(n);return head;/6-统计库存数int kcnum(struct booklist*head)int i=0;struct booklist*p;for(p=head;p!=NULL;p=p-next)i+;return i;/7-按编号查询信息并输出void chaxun1_(struct booklist*head,struct borrow*borrow_head,struct prebor_stu*pre_head)char a10;struct booklist*p;struct borrow*b;struct prebor_stu p1;int x1,x2;p=head;x1=x2=0;printf(请输入要查询的图书编号:”);gets(a);while(strcmp(p-num,a)!=0)&p-next!=NULL)p=p next;if(strcmp(p-num,a)!=0)printf(”没有找到编号为%s 的图书!n”,a);elsefor(b=borrow_head;b!=NULL;b=b next)if(strcmp(b-borbook_num,a)=0)x1=1;printf(您要查询的书已借出,其具体信息如下:n);printfb1_(b);/输出单个借出图书的数据printf1_(p);for(p1=pre_head;p1!=NULL;p1=p1-next)if(strcmp(p1-prebook_num,a)=0)x2=1;printf(您要查询的书已预借,其具体信息如下:n);printfp1_(p1);/输出单个被预借出图书的数据printf1_(p);if(x1=0&x2=0)printf(”此书未被预借!nn);printf(您要查询的图书信息如下:n);printf1_(p);/7按作者查询信息voidchaxun2_(structbooklist head,structprebor_stu pre_head,*borrow_head)char a10;struct booklist*p;struct borrow*b;struct prebor_stu*pre;int flag=1,x1;printf(请输入要查询的图书的作者:);gets(a);for(p=head;p!=NULL;p=p-next)if(strcmp(p zuozhe,a)=0)if(flag=1)printf(您查询的s 的所有图书信息如下:nn,a);flag=-1;printf1_(p);for(b=borrow_head;b!=NULL;b=b-next)if(strcmp(b borbook_num,p num)=0)printfb1_(b);x1=0;for(pre=pre_head;pre!=NULL;pre=pre-next)structborrowif(strcmp(pre prebook_num,p num)=0)printf(”此书已被s 学号的学生预借!n,pre-prestu_num);x1=1;if(x1=0)printf(”此书未被预借!n”);x1=1;printf(nn);if(flag=1)printf(”没有找到您要查询的的图书信息!nn);/7-查询某类别图书信息并自动输出voidchaxun3_(structbooklist head,structprebor_stu*pre_head,struct*borrow_head)char a10;struct booklist p;struct prebor_stu*pre;struct borrow*b;int flag=1,x1;printf(请输入要查询的图书的类别:”);gets(a);for(p=head;p!=NULL;p=p next)if(strcmp(p-leibie,a)=0)if(flag=1)printf(”您查询的%s 的所有图书信息如下:nn,a);flag=1;printf1_(p);for(b=borrow_head;b!=NULL;b=b next)if(strcmp(b-borbook_num,p-num)=0)printfb1_(b);borrowx1=0;for(pre=pre_head;pre!=NULL;pre=pre-next)if(strcmp(pre prebook_num,p num)=0)printf(此书已被%s 学号的学生预借!n”,pre prestu_num);x1=1;if(x1=0)printf(”此书未被预借!n”);x1=1;printf(nn”);if(flag=1)printf(”没有找到您要查询的的图书信息!nn);/7-按学号查询图书借阅信息并自动输出void chaxun4_(struct borrow*borrow_head,struct prebor_stu*pre_head,struct booklist head)/建立图书编号结构体struct book_numchar booknum10;struct book_num next;struct prebor_stu*p;struct borrow b;struct booklist p2;char a15;int i,j;i=j=0;struct book_num bnumhead1,*bnumhead2,*tail,p1;bnumhead1=bnumhead2=tail=p1=NULL;printf(”请输入学生学号:”);gets(a);for(p=pre_head;p!=NULL;p=p-next)if(strcmp(p-prestu_num,a)=0)i+;p1=(struct book_num*)malloc(sizeof(struct book_num);strcpy(p1 booknum,p-prebook_num);if(bnumhead1=NULL)bnumhead1=p1;elsetail-next=p1;tail=p1;p1-next=NULL;for(b=borrow_head;b!=NULL;b=b next)if(strcmp(b-stu_num,a)=0)j+;p1=(struct book_num)malloc(sizeof(struct book_num);strcpy(p1-booknum,bborbook_num);if(bnumhead2=NULL)bnumhead2=p1;elsetail next=p1;tail=p1;p1 next=NULL;if(i=0&j=0)printf(”没有您要查询学生的借阅信息!);elseif(j!=0)printf(”该生一共借了%d 本书,其借阅书的信息如下:n”,j);for(p1=bnumhead2;p1!=NULL;p1=p1 next)for(p2=head;p2!=NULL;p2=p2-next)if(strcmp(p1 booknum,p2-num)=0)printf1_(p2);if(strcmp(p2-condition,”借出”)=0)for(b=borrow_head;b!=NULL;b=b next)if(strcmp(b-borbook_num,p2-num)=0)printfb1_(b);printf(n”);if(i!=0)printf(该生一共预借借了d 本书,其借阅书的信息如下:n,i);for(p1=bnumhead1;p1!=NULL;p1=p1 next)for(p2=head;p2!=NULL;p2=p2-next)if(strcmp(p1-booknum,p2 num)=0)printf1_(p2);if(strcmp(p2-condition,”借出”)=0)for(b=borrow_head;b!=NULL;b=b-next)if(strcmp(b-borbook_num,p2-num)=0)printfb1_(b);printf(n”);/9-删除数据struct booklist*shanchu(struct booklist head,struct borrow*borrow_head,structprebor_stu*pre_head)struct booklist p1,*p2;struct borrowb;struct prebor_stu*p;char a10;p1=p2=head;printf(”请输入要删除的图书编号:);gets(a);while(strcmp(p1 num,a)!=0)p1-next!=NULL)p2=p1;p1=p1 next;if(strcmp(p1-num,a)!=0)printf(没有找到要删除的图书信息!n);else if(p1=head)head=p1-next;printf(”删除成功!n”);store(head);for(b=borrow_head;b!=NULL;b=b-next)if(strcmp(b borbook_num,a)=0)borrow_head=shanchu2_(borrow_head,b);for(p=pre_head;p!=NULL;p=p-next)if(strcmp(p prebook_num,a)=0)pre_head=shanchu3_(pre_head,p);elsep2 next=p1 next;printf(删除成功!n”);store(head);for(b=borrow_head;b!=NULL;b=b next)if(strcmp(b borbook_num,a)=0)borrow_head=shanchu2_(borrow_head,b);for(p=pre_head;p!=NULL;p=p next)if(strcmp(p-prebook_num,a)=0)pre_head=shanchu3_(pre_head,p);return head;/删除一个 struct borrow 结构体的数据struct borrow*shanchu2_(struct borrow borrow_head,struct borrow p)struct borrow*p1,p2;p1=p2=borrow_head;while(strcmp(p1-borbook_num,p borbook_num)!=0)p2=p1;p1=p1 next;if(p1=borrow_head)borrow_head=p1-next;borstore(borrow_head);elsep2-next=p1 next;borstore(borrow_head);getchar();return borrow_head;/添加一个 struct borrow 结构体的数据struct borrow*tianjia1_(struct borrow borrow_head,struct booklist*p)struct borrow*p1,p2;p1=borrow_head;p2=(struct borrow)malloc(sizeof(struct borrow);while(p1 next!=NULL)p1=p1-next;strcpy(p2 borbook_num,p num);strcpy(p2-borbook_name,p-name);printf(”借阅编号为%s 的图书的借阅信息:n,p-num);printf(”请输入应归还时间:”);gets(p2 return_time);printf(”请输入学生学号:”);gets(p2-stu_num);printf(”请输入学生姓名:”);gets(p2 stu_name);p1-next=p2;p2-next=NULL;borstore(borrow_head);return borrow_head;/删除一个 struct prebor_stu 结构体的数据struct prebor_stu shanchu3_(struct prebor_stu pre_head,struct prebor_stu p)struct prebor_stu*p1,p2;p1=p2=pre_head;while(strcmp(p1 prebook_num,p prebook_num)!=0)p2=p1;p1=p1 next;if(p1=pre_head)pre_head=p1-next;prestore(pre_head);elsep2 next=p1-next;prestore(pre_head);getchar();return pre_head;/10-修改数据void xiugai(struct booklist head,struct borrow*borrow_head,struct prebor_stu pre_head)char a10;int k,n,x=1;struct booklist p;struct borrow*b;struct prebor_stu pre;p=head;while(x)system(cls);printf(请输入要修改的图书的编号:”);gets(a);while((strcmp(p num,a)!=0)&p-next!=NULL)p=p next;if(strcmp(p num,a)!=0)printf(没有找到要删除的图书信息!n);elseprintf(”*欢迎使用君宁图书修改系统*n”);printf(*0-放弃修改*n);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(”*祝您使用愉快*n”);printf(”请选择功能:);scanf(”d,&k);getchar();switch(k)case 0:x=0;break;case 1:printf(”请输入新编号:”);gets(p-num);printf(”修改成功!n);if(strcmp(p condition,借出”)=0)for(b=borrow_head;b!=NULL;b=b next)if(strcmp(b borbook_num,a)=0)strcpy(b-borbook_num,p-num);borstore(borrow_head);for(pre=pre_head;pre!=NULL;pre=pre-next)if(strcmp(pre-prebook_num,a)=0)strcpy(pre-prebook_num,p num);prestore(pre_head);getchar();break;case 2:printf(”请输入新书名:”);gets(p name);printf(”修改成功!n”);getchar();break;case 3:printf(”请输入新作者:”);gets(p-zuozhe);printf(”修改成功!n);getchar();break;case 4:getchar();printf(请输入新类别:);gets(p leibie);printf(”修改成功!n”);getchar();break;case 5:printf(”请输入新出版时间:);gets(p pub_time);printf(修改成功!n);getchar();break;case 6:printf(”请输入新价格:);gets(p-price);printf(”修改成功!n);getchar();break;case 7:printf(”请输入新状态:”);gets(p condition);printf(修改成功!n);if(strcmp(p-condition,”在馆)=0)for(b=borrow_head;b!=NULL;b=b-next)if(strcmp(b borbook_num,p num)=0)borrow_head=shanchu2_(borrow_head,b);if(strcmp(p condition,”借出”)=0)borrow_head=tianjia1_(borrow_head,p);getchar();break;case 8:printf(”请输入新编号:);gets(p-num);if(strcmp(p-condition,借出”)=0)for(b=borrow_head;b!=NULL;b=b-next)if(strcmp(b-borbook_num,a)=0)strcpy(b-borbook_num,p-num);borstore(borrow_head);for(pre=pre_head;pre!=NULL;pre=pre-next)if(strcmp(pre-prebook_num,a)=0)strcpy(pre prebook_num,p-num);prestore(pre_head);getchar();printf(”请输入新书名:”);gets(p-name);printf(”请输入新作者:);gets(p-zuozhe);printf(”请输入新类别:”);gets(p leibie);printf(请输入新出版时间:”);gets(p-pub_time);printf(请输入新价格:”);gets(p-price);printf(”请输入新状态:);gets(p-condition);printf(”修改成功!n);if(strcmp(p-condition,”在馆”)=0)for(b=borrow_head;b!=NULL;b=b-next)if(strcmp(b borbook_num,p-num)=0)borrow_head=shanchu2_(borrow_head,b);if(strcmp(p-condition,”借出”)=0)borrow_head=tianjia1_(borrow_head,p);getchar();break;default:printf(您的输入有误!n”);getchar();break;printf(输入0 结束录入!(输入其他数字继续录入。.。)nn);printf(”请选择功能:);scanf(”%d”,&n);if(n=0)x=0;store(head);/8将图书的数据到顺序排放的链表中,且插入后也是顺序排放的struct booklist*charu(struct booklist*head,struct borrowborrow_head)struct booklist p,*p1,p2;p=scanf1_();if(strcmp(p condition,”借出”)=0)borrow_head=tianjia1_(borrow_head,p);p1=head;p2=p1;while(strcmp(p1-num,p-num)next!=NULL)p2=p1;p1=p1-next;if(p1=head)p-next=head;head=p;else if(strcmp(p1-num,p num)next=p;p-next=NULL;elsep2-next=p;p-next