图书管理c语言版.docx

上传人:文*** 文档编号:68230627 上传时间:2022-12-27 格式:DOCX 页数:92 大小:98.24KB
返回 下载 相关 举报
图书管理c语言版.docx_第1页
第1页 / 共92页
图书管理c语言版.docx_第2页
第2页 / 共92页
点击查看更多>>
资源描述

《图书管理c语言版.docx》由会员分享,可在线阅读,更多相关《图书管理c语言版.docx(92页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、#include#inc lude#includestruct tushu/*图书结构体*/char num10;/*编号*/char name20;/*书名*/char writer20;/*作者*/char press20;/*出版社*/char kind20;/*类别*/double time;/*时间*/double price;/*价格*/struct tushu *next;);struct stu/*学生结构体*/(int snum;/*学号*/char mima10;/*密码*/struct stu *next;);FILE *fp;/*图书文件*/FILE *fpl;/*管理

2、员信息文件*/FILE *fp2;/*学生信息文件*/void menu();/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/void xmenu();/*学生主菜单(学生进入可对图书,密码进行操作)*/void gfind();/*管理员查询(管理员可按一定的方式查询图书)*/void xfind();/*学生查询(学生可按一定的方式查询图书)*/ void secret();/*管理员权限(管理员登陆所用,输入错误次数过多自动退出)*/void sort();/*排序(管理员可按一定的方式对图书进行排序,排序完之后可选择文件进行保存)*/void fjprint(struct

3、 tushu *head);添加可用)*/void fprint_(struct tushu *head);改,删除,排序后用)*/void hfprint(struct tushu *head);后自动保存到文件)*/void jfprint_(struct tushu *head);之后自动从图书馆删除)*/struct tushu * Input();书的添加)*/*保存(可追加的保存,如/*保存(可覆盖保存如修/*还书保存(还书成功/*借书保存(借书成功/*图书添加(可进行图/*从文件创建链表(从struct tushu * create();文件中读出信息,建立单链表)*/void

4、gBrowse(struct tushu *head);进行遍历)*/void xBrowse(struct tushu *head);书进行遍历)*/void count(struct tushu *head);对图书进行统计)*/void Findofhame(struct tushu *head);void Findofwriter(struct tushu *head);void Findofkind(struct tushu *head);void xFindofhame(struct tushu *head);/*管理员浏览(对图书/*学生浏览(学生对图/*统计数量(管理员可/*按

5、书名查找*/*按作者查找*/*按类别查找*/*学生按书名查找*/void xFindofwriter(struct tushu *head);/*学生按作者查找*/ void xFindofkind(struct tushu *head);/*学生按类别查找*/void Sort_time(struct tushu * head);/*按时间排序(管理员按时间对图书进行排序,排序完之后可选择文件进行保存)*/ void Sort_price(struct tushu * head);/*按价格排序*/void Sort_num(struct tushu * head);/*按编号排序*/voi

6、d Delete(struct tushu * head,char m15);/*按编号删除(管理员可按编号删除图书)*/void Revise(struct tushu *head);/*修改(管理员可对图书进行修改,并选择是否保存)*/void borrow(struct tushu *head);/*借书*/void huanshu();/*还书(学生借完书之后进行还书,若没有图书则不能借)*/void gxinxiO;/*管理员信息(有管理员的账号及密码,可进行修改)*/void xmima(struct stu *headl);/*学生密码修改(学生可对自己的密码进行修改)*/str

7、uct stu * xcreate();/*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/void xsecret(struct stu *headl);/*学生权限(学生登陆所用)*/void menu。/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/(int choice,n=0;struct tushu *head;struct stu *headl,*p;char m15;there:printf(I II I n);printf(|socat图书管理系printfif1 I n);printfifI40退出系统I n”);printfif11n);print

8、/1帮助1n);printfif11n);printfif1浏览图书I n”);printfif11n);print/143统计图书数目1n);printfif11n);printfifI”4查询I n”);printfif1print”1n);15添力口print/1n);1print/1n);16排序printf(1n);1print”1n);17修改print/1n);1print/1n);18删除printf(1n);1print”19修改账号及密码1n);print/1n);1print/110学生信息n);printfif1n);printf(请选择:);fflush(stdin)

9、;head=create();scanf(%d,&choice);ifi(choice=l)/help();printf(没有内容!n);system(pause);system(cls);menu();else ififchoice-2)system(cls);if(head=NULL)(printf(没有图书,请先添加图书!n);system(pause);system(cls);menu();gBrowse(head);)else if(choice=3)(system(cls);count(head);)else if(choice=4)|system(cls);if(head=NUL

10、L)printff没有图书,请先添加图书!n”);systemCpause*);system(cls);menu();gfind();else ifchoice-5)Input();else ifi(choice=6)system(cls);if(head=NULL)(printf(没有图书,请先添加图书!n);system(pause);system(cls);menu();)sort(head);else ifi(choice=7)(system(cls);if(head=NULL)printf(没有图书,请先添加图书!n”);system(pause);system(cls);menu(

11、);Revise(head);else if(choice=8)if(head=NULL)printf(没有图书,请先添加图书!n) system(pause);system(cls);menu();printf(请输入想要删除的图书编号:”);scanf(%s,m);Delete(head,m);else ifi(choice-9)gxinxi();else if(choice=10)(system(cls);headl=xcreate();if(head 1=NULL)printf(没有学生信息,请到 xuesheng_list.txt 添加!n);system(pause);system

12、(cls);menu();fbr(p=headl ;p!=NULL;p=p-next)(printf(学生学号密码n);print 4%d %sn,p-snum,p-mima);)system(pause);system(cls);menu();)else if(choice=0)system(cls);printf(nnnn);printf(感谢使用图书管理系统nnn);exit(O);elsesystem(cls);printf(nnnn输入错误,请重新输入!nnn );system(pause);system(cls);n+;ifi(n=3)(printsnnn你错误次数太多,自动退出!

13、nnn);print”感谢使用图书管理系统nnn);system(pause);exit(O);goto there;)void xmenu()/*学生主菜单(学生进入可对图书,密码进行操作)*/(struct tushu *head;struct stu *head 1;int choice,n=0;there:printf(I II I n);printf(|socat图书借阅系统 I I n);prints|11 I n);printf(|()退出系统I n);prints|I n);printf(|1帮助1n);printff1n);1prints1n);12浏览图书print/1n)

14、;1print/1n);13查询printff1n);1prints1n);14借书print/1n);1print/1n);15还书printff1n);1prints1n);16修改密码printfifn);请选择:);printfiffflush(stdin);head=create();scanf(%d,&choice);ifi(choice=l)/xhelp();printf(没有内容!nM);system(pause);system(cls);xmenu();else if(choice=2)system(cls);if(head=NULL)printf(没有图书!n);syste

15、m(pause);system(cls);xmenu();xBrowse(head);)else if(choice=3)(if(head=NULL)(printf(没有图书!n);system(pause);system(cls);xmenu();)xfind();)else if(choice=4)(if(head=NULL)(printff 没有图书!n”);system(,pause);system(cls);xmenu();borrow(head);else ifi(choice=5)huanshu(head);else ifchoice-6)(system(cls);headl=x

16、create();if(head 1=NULL)(printf(学生信息被清空!n”);system(pause);system(cls);xmenu();xmima(headl);else ifi(choice=0)system(cls);printf(nnnn);printf(感谢使用图书管理系统nnn);exit(O);elsesystem(cls);printf(nnnn输入错误,请重新输入!nnn );system(pause);system(cls);n+;ifi(n=3)(printsnnn你错误次数太多,自动退出!nnn);print”感谢使用图书管理系统nnn);system

17、(pause);exit(O);goto there;)voidgfind()/*管理员查询(管理员可按一定的方式查询图书)*/(int choice,n=0;struct tushu *head;there:system(cls);printf(I II I n);printf(|socat图书借阅系统 I I n);prints|11 I n”);printf(|0返回I n);print/|I n);print/1按书名查找n);printfifI n); print/I n”); printfifI n); print/I n); printfifI n); printfpI n);p

18、rintfif”2按作者查找”3按类别查找print/fflush(stdin);head=create();scanf(%d,&choice);ifi(choice=l)1n);请选择:);system(cls);F indofhame(head);)else ichoice-2)(system(cls);F indofwriter(head);else ifi(choice-3)system(cls);F indofkind(head);else if(choice=0)system(cls);menu();elsesystem(cls);输入错误,请重新printf(nnnn输入!nnn

19、 );system(pause);system(cls);n+;ififn=3)print/nnn你错误次数太多,自动退出!nnn);print”感谢使用图书管理系统nnn);system(pause);exit(O);goto there;)void xfind()/*学生查询(学生可按一定的方式查询图书)*/(struct tushu *head;int choice,n=0;there:system(clsn);I II I n);printf(|socat 图书借阅系统 I I n);print/|11 I n);printf(|()返回I n);prints|I n);printf(

20、|1按书名查找I n);print/|I n);printf(|42按作者查找I n);prints|I n);printf(|3按类别查找I n);print/|I n);printfifn);printfif1n);printf(请选择:);fflush(stdin);head=create();scanf(%d,&choice);ifi(choice=l)system(cls);xFindofhame(head);else ifi(choice=2)system(cls);xF indofwriter(head);else if(choice=3)system(cls);xFindofk

21、ind(head);else ifchoice-0)system(cls);xmenu();elsesystem(cls);printf(nnnn输入错误,请重新输入!nnn );system(pause);system(cls);n+;ifi(n=3)(printnnn你错误次数太多,自动退出!nnn);prints感谢使用图书借阅系统nnn);system(pause);exit(0);goto there;)void sort()(struct tushu *head;int choice,n=0;there:system(cls);printf(I II I n);printf(|so

22、cat图书借阅系统 I I n);prints|11 I n);printf(|0返回I n);printf(|I n);printf(|1按时间排序I n);printf(|I n);printf(11n);2按价格排序printf(1printf(1n);13按编号排序printf(1n);1printf(1n);1printf(1n);1n);printf(请选择:);fflush(stdin);head=create();scanf(%d,&choice);ifi(choice=l)system(cls);Sorttime(head);else ifchoice-2)system(cl

23、s);Sort_price(head);else if(choice=3)system(cls);Sortnum(head);else ifi(choice=0)(system(cls);menu();elsesystem(cls);输入错误,请重新printf(nnnn输入!nnn );system(pause);system(cls);n+;ififn=3)(printnnn你错误次数太多,自动退出!nnn);printf(感谢使用图书借阅系统nnn);system(pause);exit(O);goto there;)struct tushu *Input()(struct tushu

24、*p 1,*p2,*head,*ptr;char num;int x,i=0;system(cls);pl=(struct tushu *)malloc(sizeof(struct tushu);head=p 1;p 1-price=-1;while(i!=l)printf(请输入编号,以并结束n);scanf(%s,p 1-num);if(strcmp(p 1-num,#)=O)i=l;while(i!=l)(printf(请依次输入书名作者出版社类别出版时间价格n”);scanf(%s%s%s%s%lf%lf,p 1-name,p 1-writer,p 1-press,p 1-kind,&

25、p l-time,&p 1-price);p2=pl;pl=(struct tushu *)malloc(sizeoinstruct tushu);p2-next=p 1;break;)if(pl-price!=-l)p2-next=NULL;elsehead=NULL;system(cls);printf(nnnttt 图书信息输入结束!nnn);system(pause);system(cls);printf(”nnnttt 是否保存图书信息?(1.是/2.否):);scanf(%d,&x);if(x=l)fprint(head);else(systemCcls*);printf(nnnt

26、tt 文件没有被保存!nnnn);system(pause);system,cis);menu();)void fprint(struct tushu *head)struct tushu *pl;if(fp=fbpen(tushu_li st.txt7a)=NULL)printfi(File open error!n);exit(O);if(head=NULL)printf(没有图书保存!n);system(pause);system(cls);menu();for(pl=head;pl !=NULL;pl=pl-next)/*遍历*/fprintf(fp,%st%st%st%st%st%.

27、01ft%lfn,p 1-num,p 1-name,p 1-writer,p 1-press,p 1-kind,p l-time,p 1-pr ice );/*将图书信息写入文件*/fclose(fp);system(cls);printf(n图书信息已成功保存到文件tushu_list.txt中!n);system(pause);system(cls);getchar();menu();void fprint_(struct tushu *head)struct tushu *p 1;char a20;printf(请输入你保存的文件!n);scanf(%s,a);if(fp=fbpen(a

28、, w)=NULL)printfi(File open error!n);exit(O);if(head=NULL)system(cls);printf(没有图书!n);system(pause);system(cls);menu();for(p 1=head;p 1!=NULL;p l=p 1-next)fprintf(fp,%st%st%st%st%st%.01ft%lfn,p 1-num,p 1-name,p 1-writer,p l-press,p 1-kind,p l-time,p l-price );/*将图书信息写入文件*/fclose(fp);system(cls);print

29、f(n图书信息已成功保存到文件%s中!n,a);system(pause);system(cls);menu();)void hfprint(struct tushu *head)(struct tushu *p 1;if(fp=fopen(tushu_list.txt,a)=NULL)printfi(File open error!n);exit(O);if(head=NULL)(printf(没有还书!n);xmenu();for(pl=head;pl !=NULL;pl=pl-next)/*遍历*/fprintf(fp,%st%st%st%st%st%.01ft%lfn,p 1-num,

30、p 1-name,p 1-writer,p 1-press,p 1-kind,p l-time,p l-pr ice );/*将图书信息写入文件*/fclose(fp);xmenu();)void jfprint_(struct tushu *head)(struct tushu *p 1;if(fp=fopen(tushu_list.txt,w)=NULL)printFile open error!n);exit(O);if(head=NULL)xmenu();for(p 1=head;p 1!=NULL;p 1=p 1-next)(fprintf(fp,%st%st%st%st%st%.O

31、lft%lfn, p 1-num,p 1-name,p 1-writer,p l-press,p 1-kind,p l-time,p l-pr ice );/*将图书信息写入文件*/fclose(fp);system(cls);getchar();xmenu();struct tushu * create()struct tushu *head=NULL,*p,*pl,*p2;if(fp=fbpen(tushuist.txt,r)=NULL)/*先安全打开目录文件*/printf(File open error!n);exit(O);while(! feof(fp)/*读取并创建链表*/(p=

32、(struct tushu *)malloc(sizeof(struct tushu);p-price=-1;fscanf(fp,%s%s%s%s%s%lf%lf, p-num,p-name,p-writer,p-press,p-kind,&p-time,&p-price);if(p-price=-1)free(p);break;)if(head=NULL)(head=p;P1=P;p 1-next=NULL;elsepl-next=p;p2=pl;P1=P;p 1-next=NULL;)fclose(fp);return head;void gBrowse(struct tushu *hea

33、d)struct tushu *p 1;for(p 1=head;p 1!=NULL;pl p 1-next)(printf(编号书名作者出版社类别出版时间价格n);printf(%st%st%st%st%st%.01ft%.21fn,p 1-num,p 1-name,p 1-writer,p 1-press,p 1-kind,p 1-time,p 1-pr ice);)system(pause);system(cls);menu();void xBrowse(struct tushu *head)(struct tushu *p 1;for(pl=head;p 1!=NULL;p 1=p 1

34、-next)printf(编号书名作者出版社类别出版时间价格n”);printf(%st%st%st%st%st%.01ft%.21fn,p 1-num,p 1-name,p 1-writer,p 1-press,p 1-kind,p l-time,p l-pr ice);)system(pause);system(cls);xmenu();void count(struct tushu *head)/*统计图书数目*/int n=0;struct tushu *p 1;for(pl=head;p 1!=NULL;p 1=p 1-next)n+;printf(n此系统统计在内的图书共有%d册。

35、n,n);/*计算并输出图书数目*/system(pause);system(cls);menu();void Findofhame(struct tushu *head)/*按书名查询图书*/int i=O,n;char b20;struct tushu *p;p=head;printf(n请输入要查询的图书名称:”);scanf(%s,b);while(p !=NULL)(iffstrcmp (p-name ,b)=0)(printf(n编号书名作者出版社类别出版时间价格叫;printf(%st%st%st%st%st%.01ft%.21fn”,p-num,p-name,p-writer,

36、p-press,p-kind,p-time,p-price);i+;p=p-next;)if(i=O)(system(cls*);printf(n对不起!没有找到名为s的图书!n,b);system(pause);)printf(nnnttt是否继续查找图书信息?(1.是/其他返回):”);scanf(%d,&n);if(n=l)gfind();elsesystem(cls);menu();)void Findofwriter(struct tushu *head)(int i=0,n;char b20;struct tushu *p;p=head;printf(n请输入要查询的图书作者姓名:

37、);scanf(%s,b);while(p!=NULL)if(strcmp(p-writer,b)=O)printf(n编号书名作者出版社类别出版时间价格n”);printf(%st%st%st%st%st%.01ft%.21fn”,p-num,p-name,p-writer,p-press,p-kind,p-time,p-price);i+;)p=p-next;)if(i=O)(system(cls);printf(n对不起!没有找到,%s,所著的相关图书!n”,b); system(pause);printf(nnnttt是否继续查找图书信息?(1.是/其他.返回):”);scanf(%d

38、,&n);if(n=l)gfind();elsesystem(cls);menu();)void Findofkind(struct tushu *head)(int i=0,n;char b20;struct tushu *p;p=head;printf(n请输入您要查询的图书类别:”);scanf(%s,b);while(p!=NULL)(if(strcmp(p-kind,b)=O)printf(n编号书名作者出版社类别出版时间价格n);printf%st%st%st%st%st%.01ft%.21fn”,p-num,p-name,p-writer,p-press,p-kind,p-time,p-price);i+;p=p-next;)if(i=O)(system(cls);printf(n对不起!没有找到类别为,s,的图书!n,b);system(pause);)printf(nnnttt是否继续查找图书信息?(1.是/其他.返

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com