收藏 分销(赏)

C语言图书标准管理系统代码.doc

上传人:精*** 文档编号:2993297 上传时间:2024-06-12 格式:DOC 页数:42 大小:80.54KB
下载 相关 举报
C语言图书标准管理系统代码.doc_第1页
第1页 / 共42页
C语言图书标准管理系统代码.doc_第2页
第2页 / 共42页
C语言图书标准管理系统代码.doc_第3页
第3页 / 共42页
C语言图书标准管理系统代码.doc_第4页
第4页 / 共42页
C语言图书标准管理系统代码.doc_第5页
第5页 / 共42页
点击查看更多>>
资源描述

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);printf

5、( =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); s

6、canf(%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(请输入所选择序号:); scanf

7、(%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(head=

9、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); getchar()

10、; 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;default:print

11、f( 您输入有误! 请重新输入!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(请输入作者名:); sca

12、nf(%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);strcpy(p-pr

13、ess,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(请输入作者名:);sc

14、anf(%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; char bname50

15、,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(请输入出版社:); sca

16、nf(%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=time;p-price

17、=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;if(p=NULL)re

18、turn 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);fclose(fp);/

19、从文件中读取图书信息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-press,p1-so

20、rt,&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( 编号 图书名 作者名 出版社 类别 出版时间 价格n);for(p

21、tr=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=NULL) /对于文件中只

22、有一组数据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(head); printf(删除成

24、功!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-按图书类别查询 4-按作者名查询 *

25、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(您输入有误!n);break;/按编号查

26、询图书信息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 %s %s %d %.2f *n,p-nu

27、m,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(struct book *head)ch

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 通信科技 > 开发语言

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

关于我们      便捷服务       自信AI       AI导航        获赠5币

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

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

gongan.png浙公网安备33021202000488号   

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

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服