c语言-图书管理系统(1).doc_第1页
c语言-图书管理系统(1).doc_第2页
c语言-图书管理系统(1).doc_第3页
c语言-图书管理系统(1).doc_第4页
c语言-图书管理系统(1).doc_第5页
免费预览已结束,剩余10页可下载查看

下载本文档

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

文档简介

#include#include#includetypedef struct linkchar number100;char bookname100;char author100;char publish100;char time100;char status100;float price;struct link *next;link;link *Cbook();void mainmenu();void menu1();void glmenu();void cxmenu();void jhmenu();void print(link*head);void hold(link*head);void holdcx(link*t);link *findnumber(link*head);link *findbookname(link*head);link *findauthor(link*head);link *add(link*head);link *sortnumber(link*head);link *delbook(link*head);link *revamp(link*head);link *borrowbook(link*head);link *returnbook(link*head);int main()int a,b,c,d,e;link *h,*t;L:system(cls); mainmenu(); while(1) scanf(%d,&a); switch(a) case 1: B:system(cls); menu1(); while(1) scanf(%d,&b); switch(b) case 1: h=Cbook(); break; case 2: system(cls); glmenu(); while(1) scanf(%d,&c); switch(c) case 1: print(h); break; case 2: h=add(h); h=sortnumber(h); print(h); break; case 3: revamp(h); break; case 4: h=delbook(h); print(h); break; case 5: hold(h); break; case 6: goto B; break; break; case 3: system(cls); cxmenu(); while(1) scanf(%d,&d); switch(d) case 1: print(h); break; case 2: t=findnumber(h); if(t=NULL) printf(抱歉,没有找到您要查询的图书!); else printf(您想要查询的为:); printf(n); printf(n*n); printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n); printf(n); printf(%st%st%st%st%st,t-number,t-bookname,t-author,t-publish,t-time); printf(tt%.2f,t-price); printf(tt%s,t-status); break; case 3: t=findbookname(h); if(t=NULL) printf(抱歉,没有找到您要查询的图书!); else printf(您要查询的图书为:); printf(n); printf(n*n); printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n); printf(n); printf(%st%st%st%st%st,t-number,t-bookname,t-author,t-publish,t-time); printf(tt%.2f,t-price); printf(tt%s,t-status); break; case 4: t=findauthor(h); if(t=NULL) printf(抱歉,没有找到您要查询的图书!); else printf(您要查询的图书为:); printf(n); printf(n*n); printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n); printf(n); printf(%st%st%st%st%st,t-number,t-bookname,t-author,t-publish,t-time); printf(tt%.2f,t-price); printf(tt%s,t-status); break; case 5: holdcx(t); break; case 6: goto B; break; break; case 4: system(cls); jhmenu(); while(1) scanf(%d,&e); switch(e) case 1: borrowbook(h); break; case 2: returnbook(h); break; case 3: goto B; break; break; case 5: hold(h); break; case 6: system(cls); menu1(); break; case 7: goto L; break; break; case 0: printf(ttt感谢您的使用,再见!); exit(0); ; return 0; link *Cbook()int n=0;link *p,*q,*head;FILE *fp;fp=fopen(图书信息.txt,r+);if(fp=NULL)printf(没有找到文件,请检查.);p=(link *)malloc(sizeof(link);if(p=NULL)printf(申请内存出错!n);fscanf(fp,%s%s%s%s%s,p-number,p-bookname,p-author,p-publish,p-time);fscanf(fp,%f,&p-price);fscanf(fp,%s,p-status);while(feof(fp)=0)n+;if(n=1)head=p;elseq=p;p=(link *)malloc(sizeof(link);if(p=NULL)printf(申请内存出错!n);fscanf(fp,%s%s%s%s%s,p-number,p-bookname,p-author,p-publish,p-time); fscanf(fp,%f,&p-price); fscanf(fp,%s,p-status); q-next=p;p-next=NULL;fclose(fp);printf(信息已录入!);return head;void mainmenu()printf(n*n);printf(n 欢迎使用图书管理系统 n);printf(n 1.进入系统 n);printf(n 0.退出系统 n);printf(n*n);printf(n请选择:);void menu1()printf(n*n);printf(n 1.录入所有图书信息 n);printf(n 2.进入图书管理系统 n);printf(n 3.进入图书查询系统 n);printf(n 4.进入图书借还系统 n);printf(n 5.保存所有图书信息 n);printf(n 6.显示菜单 n);printf(n 7.返回上级菜单 n);printf(n*n);printf(请选择:);void glmenu()printf(n*n); printf(n 1.显示所有图书信息 n);printf(n 2.添加一本图书信息 n);printf(n 3.修改一本图书信息 n);printf(n 4.删除一本图书信息 n);printf(n 5.保存所有图书信息 n);printf(n 6.返回上级菜单 n);printf(n*n);printf(请选择:);void cxmenu()printf(n*n); printf(n 1.显示所有图书信息 n);printf(n 2.按编号查询图书 n);printf(n 3.按书名查询图书 n);printf(n 4.按作者查询图书 n);printf(n 5.保存所查询图书信息 n);printf(n 6.返回上级菜单 n);printf(n*n);printf(请选择:);void jhmenu()printf(n*n);printf(n 1.借书 n);printf(n 2.还书 n);printf(n 3.返回上级菜单 n);printf(n*n);printf(请选择:);void print(link *head)link *p;p=head;if(p=NULL)printf(文件中没有图书信息n);elseprintf(n);printf(n*n);printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n);while(p!=NULL)printf(n); printf(%stt%stt%stt%stt%s,p-number,p-bookname,p-author,p-publish,p-time);printf(tt%.2f,p-price);printf(tt%s,p-status);printf(n);p=p-next;void hold(link *head)link *p;FILE *fp;fp=fopen(图书信息.txt,w+);if(fp=NULL)printf(文件操作出错!);exit(1);p=head;for(;p!=NULL;p-next)fprintf(fp,n);fprintf(fp,%stt%stt%stt%stt%s,p-number,p-bookname,p-author,p-publish,p-time);fprintf(fp,tt%.2f,p-price);fprintf(fp,tt%s,p-status);fclose(fp);printf(信息已保存!);void holdcx(link *t)link *p=NULL;FILE *fp;fp=fopen(查询.txt,a+);p=t;fprintf(fp,查询到的信息为:n);fprintf(fp,n);fprintf(fp,n*n);fprintf(fp,n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n);fprintf(fp,n);fprintf(fp,%stt%stt%stt%stt%s,p-number,p-bookname,p-author,p-publish,p-time);fprintf(fp,tt%.2f,p-price);fprintf(fp,tt%s,p-status);fprintf(fp,n);fclose(fp);printf(信息已保存!);link *findnumber(link *head)char key100;link *h,*t1=NULL;printf(请输入图书的编号:);getchar();gets(key);for(h=head;h!=NULL;h=h-next)if(strcmp(key,h-number)=0)t1=h;break;return t1;link *findbookname(link *head)char key100;link *h,*t2=NULL;printf(请输入图书的书名:);getchar();gets(key);for(h=head;h!=NULL;h=h-next)if(strcmp(key,h-bookname)=0)t2=h;break;return t2;link *findauthor(link *head)char key100;link *h,*t3=NULL;printf(请输入作者姓名:);getchar();gets(key);for(h=head;h!=NULL;h=h-next)if(strcmp(key,h-author)=0)t3=h;break;return t3;link *add(link *head)link *h,*h1;h1=head;h=(link *)malloc(sizeof(link);if(h=NULL)printf(申请内存出错!);exit(1);printf(请输入添加图书的信息:);printf(n);printf(n*n);printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n);printf(n);scanf(%stt%stt%stt%stt%s,h-number,h-bookname,h-author,h-publish,h-time); scanf(tt%f,&h-price);scanf(tt%s,h-status);h-next=h1;return h;link *sortnumber(link *head)link *p,*q,*temp;temp=(link *)malloc(sizeof(link);if(temp=NULL)printf(申请内存出错!);exit(1);for(p=head;p!=NULL;p=p-next)for(q=p-next;q!=NULL;q=q-next)if(strcmp(p-number,q-number)0)strcpy(temp-number,p-number);strcpy(temp-bookname,p-bookname);strcpy(temp-author,p-author);strcpy(temp-publish,p-publish);strcpy(temp-time,p-time);temp-price=p-price;strcpy(temp-status,p-status);strcpy(p-number,q-number);strcpy(p-bookname,q-bookname);strcpy(p-author,q-author);strcpy(p-publish,q-publish);strcpy(p-time,q-time);p-price=q-price;strcpy(p-status,q-status);strcpy(q-number,temp-number);strcpy(q-bookname,temp-bookname);strcpy(q-author,temp-author);strcpy(q-publish,temp-publish);strcpy(q-time,temp-time);q-price=temp-price;strcpy(q-status,temp-status);return head;link *delbook(link *head)int k=0;char str10;link *h,*t,*p;h=t=p=head;printf(请输入要删除的图书名:);getchar();gets(str);for(;p!=NULL;p-next)k+;if(k2)t=t-next;if(strcmp(p-bookname,str)=0)&(k=1)h=p-next;else if(strcmp(p-bookname,str)=0&k1)t-next=p-next;else if(strcmp(p-bookname,str)=0&p-next=NULL)t=NULL;return h;link *revamp(link *head)link *h,*t;h=head;t=findbookname(h);if(t=NULL)printf(没有找到.);elseprintf(修改前图书信息为:);printf(n);printf(n*n); printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n); printf(n); printf(%stt%stt%stt%stt%s,t-number,t-bookname,t-author,t-publish,t-time); printf(tt%.2f,t-price); printf(tt%s,t-status);printf(n); printf(请输入这本书(书名除外)所有信息:n); printf(n*n); printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n); printf(n); scanf(%stt%stt%stt%stt%s,t-number,t-bookname,t-author,t-publish,t-time); scanf(tt%2f,&t-price); scanf(tt%s,t-status);printf(修改后图书信息为:n);printf(n);printf(n*n); printf(n编号tt书名tt作者tt出版社tt出版时间tt价格tt状态n); printf(n); printf(%stt%s

温馨提示

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

评论

0/150

提交评论