C语言学习知识图书管理方案计划解决方法系统代码.doc

上传人:小** 文档编号:2538712 上传时间:2020-04-19 格式:DOC 页数:27 大小:91.52KB
返回 下载 相关 举报
C语言学习知识图书管理方案计划解决方法系统代码.doc_第1页
第1页 / 共27页
C语言学习知识图书管理方案计划解决方法系统代码.doc_第2页
第2页 / 共27页
点击查看更多>>
资源描述

《C语言学习知识图书管理方案计划解决方法系统代码.doc》由会员分享,可在线阅读,更多相关《C语言学习知识图书管理方案计划解决方法系统代码.doc(27页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、#include#include#includestruct bookint num;char bname50;char wname20;char press50;char sort50;int time;float price; struct book *next;struct book *creatbook(); /创建链表struct book *addbook(struct book *head); /添加图书int yanzheng(struct book *head,int m); /验证新添加的图书编码是否已存在void deletebook(struct book *head)

2、; /删除图书void fprint(struct book *head); /将链表写入文件struct book *load(); /从文件中读取信息并建成链表void print_book(struct book *head); /将链表信息输出void chaxun(struct book *head); /查询图书信息void num_chaxun(struct book *head); /按图书编号查询图书void wname_chaxun(struct book *head); /按作者名查询图书void sort_chaxun(struct book *head); /按类别查

3、询图书void time_chaxun(struct book *head); /按出版时间查询图书void bname_chaxun(struct book *head); /按图书名查询图书void xiugai(struct book *head); /修改图书信息void paixu(struct book *head); /对图书进行排序void num_paixu(struct book *head); /按图书编号排序void time_paixu(struct book *head); /按图书出版时间排序void price_paixu(struct book *head);

4、 /按图书价格排序void bname_paixu(struct book *head); /按图书名排序void wname_paixu(struct book *head); /按作者名排序int main()int choice,n,x,y=1,c,c1=1234;char a,d,b10,b110=yjk;struct book *head=NULL;while(y)system(cls); printf(nnnnnnn); printf( * 欢迎光临 *nn); printf( * 图书信息管理系统 *nnn);printf(nn);printf( =1-用户登录=n);print

5、f( =0-退出系统=n);printf( 请输入您的选择:);scanf(%d,&n);printf(n);getchar();switch(n)case 0:y=0;break;case 1: printf( 请输入您的用户名:); gets(b); printf(n); printf( 请输入您的密码:); scanf(%d,&c); printf(n); if(strcmp(b,b1)!=0|c!=c1) printf( 验证失败,请重新输入!n); scanf(%c,&d); getchar(); system(cls); else printf( 验证通过!请按Enter键进入!n

6、); scanf(%c,&d); getchar(); x=1; while(x) system(cls); printf( -n); printf( *图书信息管理系统*n); printf( -nn); printf( *nn); printf( *nn); printf( | 1-添加图书 2-删除图书 |nn); printf( | 3-图书列表 4-图书排序 |nn); printf( | 5-查询图书 6-修改图书 |nn); printf( | 7-录入数据 0-退出系统 |nn); printf( *nn); printf( *nn); printf(请输入所选择的序号:);

7、scanf(%d,&choice); getchar(); system(cls); switch(choice) case 0: x=0;break; case 1: head=load(); if(head=NULL) printf(文件为空,请先录入数据!n); getchar(); break; else head=addbook(head); printf(添加成功!n); printf(是否将新信息保存到文件?(y/n)n); scanf(%c,&a); getchar(); switch(a) case n: break; case y: fprint(head); printf

8、(保存成功!n); getchar(); break; break; case 2: head=load(); if(head=NULL) printf(文件为空,请先录入数据!n); getchar(); break; else deletebook(head); getchar(); break; break; case 3: head=load(); if(head=NULL) printf(文件为空,请先录入数据!n); getchar(); break; else print_book(head); getchar(); break; case 4: head=load(); if(

9、head=NULL) printf(文件为空,请先录入数据!n); getchar(); break; else paixu(head); getchar(); break; case 5: head=load(); if(head=NULL) printf(文件为空,请先录入数据!n); getchar(); break; else chaxun(head); getchar(); break; case 6: head=load(); if(head=NULL) printf(文件为空,请先录入数据!n); getchar(); break; else xiugai(head); getc

10、har(); break; break; case 7: printf(注意:输入图书编码为0时结束!n); head=creatbook(); printf(是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)n); getchar(); scanf(%c,&a); getchar(); switch(a) case n: break; case y: fprint(head); printf(保存成功!n); getchar(); break; break; default: printf(您的输入有误,请重新输入!n); getchar(); break;break;defau

11、lt:printf( 您的输入有误! 请重新输入!n);getchar();break;/录入数据并形成链表struct book *creatbook()struct book *head,*tail,*p;int num,time,n;char bname50,wname20,press50,sort50;float price;int size=sizeof(struct book);head=tail=NULL;printf(请输入图书编号:);scanf(%d,&num); printf(请输入图书名:); scanf(%s,bname);getchar(); printf(请输入作

12、者名:); scanf(%s,wname);getchar(); printf(请输入出版社:); scanf(%s,press);getchar();printf(请输入类别:); scanf(%s,sort);getchar(); printf(请输入出版时间:); scanf(%d,&time);getchar(); printf(请输入价格:); scanf(%f,&price);getchar();while(1)p=(struct book *)malloc(size);p-num=num;strcpy(p-bname,bname);strcpy(p-wname,wname);st

13、rcpy(p-press,press);strcpy(p-sort,sort);p-time=time;p-price=price;p-next=NULL;if(head=NULL)head=p;elsetail-next=p;tail=p;do printf(请输入图书编号:); scanf(%d,&num);n=yanzheng(head,num);if(n=0)break;elseprintf(您输入的编号已存在,请重新输入!n);while(1);if(num=0)break;else printf(请输入图书名:);scanf(%s,bname);getchar();printf(请

14、输入作者名:);scanf(%s,wname);getchar();printf(请输入出版社:);scanf(%s,press);getchar();printf(请输入类别:);scanf(%s,sort);getchar();printf(请输入出版时间:);scanf(%d,&time);getchar();printf(请输入价格:);scanf(%f,&price);getchar();return head;/插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head)struct book *ptr,*p1,*p2,*p; ch

15、ar bname50,wname20,press50,sort50;int size=sizeof(struct book); int num,time,n=1;float price;do printf(请输入图书编号:); scanf(%d,&num);n=yanzheng(head,num);if(n=0)break;elseprintf(您输入的编号已存在,请重新输入!n);while(1); printf(请输入图书名:); scanf(%s,bname);getchar(); printf(请输入作者名:); scanf(%s,wname);getchar(); printf(请输

16、入出版社:); scanf(%s,press);getchar();printf(请输入类别:); scanf(%s,sort);getchar(); printf(请输入出版时间:); scanf(%d,&time);getchar(); printf(请输入价格:); scanf(%f,&price);getchar();p=(struct book *)malloc(size); p-num=num; strcpy(p-bname,bname);strcpy(p-wname,wname);strcpy(p-press,press);strcpy(p-sort,sort);p-time=t

17、ime;p-price=price;p2=head;ptr=p;while(ptr-nump2-num)&(p2-next!=NULL)p1=p2;p2=p2-next;if(ptr-numnum)if(head=p2)head=ptr;elsep1-next=ptr; p-next=p2;elsep2-next=ptr;p-next=NULL;return head;/验证添加的图书编号是否已存在int yanzheng(struct book *head,int m)struct book *p;p=head;while(p!=NULL)if(p-num=m)break;p=p-next;

18、if(p=NULL)return 0;elsereturn 1;/将新链表写入文件中void fprint(struct book *head)FILE *fp;char ch=1;struct book *p1;if(fp=fopen(f1.txt,w)=NULL)printf(File open error!n);exit(0);fputc(ch,fp);for(p1=head;p1;p1=p1-next)fprintf(fp,%d %s %s %s %s %d %fn,p1-num,p1-bname,p1-wname,p1-press,p1-sort,p1-time,p1-price);

19、fclose(fp);/从文件中读取图书信息struct book *load()FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if(fp=fopen(f1.txt,r)=NULL)printf(File open error!n);exit(0);ch=fgetc(fp);if(ch=1) while(!feof(fp) p1=(struct book *)malloc(sizeof(struct book); fscanf(fp,%d%s%s%s%s%d%fn,&p1-num,p1-bname,p1-wname,p1

20、-press,p1-sort,&p1-time,&p1-price); if(head=NULL) head=p1; else tail-next=p1; tail=p1; tail-next=NULL; fclose(fp); return head;elsereturn NULL;/将整个链表的信息输出void print_book(struct book *head)struct book *ptr;if(head=NULL)printf(n没有信息!n);return;printf( 图书信息列表如下n);printf( =n);printf( 编号 图书名 作者名 出版社 类别 出版

21、时间 价格n);for(ptr=head;ptr;ptr=ptr-next)printf( %d %s %s %s %s %d %.2fn,ptr-num,ptr-bname,ptr-wname,ptr-press,ptr-sort,ptr-time,ptr-price);printf( =n);/删除图书信息void deletebook(struct book *head)int a;char b,ch=1;struct book *p1,*p2;FILE *fp;printf(请输入要删除的图书编号:);scanf(%d,&a); p1=head; if(p1-num=a&p1-next

22、=NULL) /对于文件中只有一组数据printf(是否清空文件!(y/n)n);getchar();scanf(%c,&b);getchar();switch(b)case n:break;case y: if(fp=fopen(f1.txt,w)=NULL) printf(File open error!n); exit(0); fclose(fp);printf(文件已清空!n);else while(p1-num!=a&p1-next!=NULL) p2=p1; p1=p1-next; if(p1-next=NULL) if(p1-num=a) p2-next=NULL; printf

23、(是否确定从文件中彻底删除该图书?(y/n)n); getchar(); scanf(%c,&b); switch(b) case n: break; case y: fprint(head); printf(删除成功!n); getchar(); break; else printf(没有找到要删除的数据!n); getchar(); else if(p1=head) head=p1-next; printf(是否确定从文件中彻底删除该图书?(y/n)n); getchar(); scanf(%c,&b); switch(b) case n: break; case y: fprint(he

24、ad); printf(删除成功!n); getchar(); break; else p2-next=p1-next; printf(是否确定从文件中彻底删除该图书?(y/n)n); getchar(); scanf(%c,&b); switch(b) case n: break; case y: fprint(head); printf(删除成功!n); getchar(); break; /图书查询void chaxun(struct book *head)int a;printf( =n);printf( * 1-按图书编号查询 2-按图书名查询 *n);printf( * 3-按图书

25、类别查询 4-按作者名查询 *n);printf( * 5-按出版时间查询 0-退出查询 *n);printf( =n);printf(请输入所选择的编号:);scanf(%d,&a);getchar();switch(a)case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf(您的输入

26、有误!n);break;/按编号查询图书信息void num_chaxun(struct book *head)int a;struct book *p; printf(请选择您要查询的图书编号:);scanf(%d,&a);getchar();p=head; while(p!=NULL)if(p-num=a)break;p=p-next;if(p=NULL)printf(没有找到该编号的图书!n);elseprintf( 你所查询的图书信息如下n);printf( =n);printf( * 编号 图书名 作者名 出版社 类别 出版时间 价格 *n);printf( * %d %s %s %

27、s %s %d %.2f *n,p-num,p-bname,p-wname,p-press,p-sort,p-time,p-price);printf( =n);/按图书名查询图书信息void bname_chaxun(struct book *head)char a50;int flag=0;struct book *p; printf(请选择您要查询的图书名:);gets(a);p=head;while(p!=NULL)if(strcmp(p-bname,a)=0)flag=1;break;p=p-next; if(flag=0)printf(没有找到该图书名的图书!n);else printf( 你所查询的图书信息如下n);printf( =n);printf( * 编号 图书名 作者名 出版社 类别 出版时间 价格 *n); while(p!=NULL)if(strcmp(p-bname,a)=0)printf( * %d %s %s %s %s %d %.2f *n,p-num,p-bname,p-wname,p-press,p-sort,p-time,p-price); p=p-next; printf( =n);/按作者名查询图书信息void wname_chaxun

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

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

本站为文档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