版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 . . . C语言图书管理系统#include<stdio.h>#include<stdlib.h>#include<string.h>struct 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 *
2、head,int m); /验证新添加的图书编码是否已存在void deletebook(struct book *head); /删除图书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 b
3、ook *head); /按作者名查询图书void sort_chaxun(struct book *head); /按类别查询图书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(str
4、uct book *head); /按图书出版时间排序void price_paixu(struct book *head); /按图书价格排序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("
5、;nnnnnnn"); printf(" * 欢迎光临 *nn"); printf(" * 图书信息管理系统 *nnn");printf("nn");printf(" =1-用户登录=n");printf(" =0-退出系统=n");printf(" 请输入您的选择:");scanf("%d",&n);printf("n");getchar();switch(n)case 0:y=0;break;case 1: pri
6、ntf(" 请输入您的用户名:"); 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(" 验证通过!请按En
7、ter键进入!n"); 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
8、-图书排序 |nn"); printf(" | 5-查询图书 6-修改图书 |nn"); printf(" | 7-录入数据 0-退出系统 |nn"); printf(" *nn"); printf(" *nn"); printf("请输入所选择的序号:"); scanf("%d",&choice); getchar(); system("cls"); switch(choice) case 0: x=0;break; case 1: h
9、ead=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("保存成功!n&
10、quot;); 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; ca
11、se 4: head=load(); if(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("文件为空,
12、请先录入数据!n"); getchar(); break; else xiugai(head); getchar(); 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'
13、: fprint(head); printf("保存成功!n"); getchar(); break; break; default: printf("您的输入有误,请重新输入!n"); getchar(); break;break;default:printf(" 您的输入有误! 请重新输入!n");getchar();break;/录入数据并形成链表struct book *creatbook()struct book *head,*tail,*p;int num,time,n;char bname50,wname20,press
14、50,sort50;float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num); printf("请输入图书名:"); scanf("%s",bname);getchar(); printf("请输入作者名:"); scanf("%s",wname);getchar(); printf("请输入:"); scanf("
15、;%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-&g
16、t;bname,bname);strcpy(p->wname,wname);strcpy(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(&qu
17、ot;您输入的编号已存在,请重新输入!n");while(1);if(num=0)break;else printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",
18、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,wname20,press50,sort50;int size=s
19、izeof(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("请输入作者名:"); scan
20、f("%s",wname);getchar(); printf("请输入:"); scanf("%s",press);getchar();printf("请输入类别:"); scanf("%s",sort);getchar(); printf("请输入出版时间:"); scanf("%d",&time);getchar(); printf("请输入价格:"); scanf("%f",&price);g
21、etchar();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=price;p2=head;ptr=p;while(ptr->num>p2->num)&&(p2->next!=NULL)p1=p2;p2=p2->next;if(ptr->nu
22、m<=p2->num)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)return 0;elsereturn 1;/将新链表写入文件中void fprint(stru
23、ct 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->
24、sort,p1->time,p1->price);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 *)mallo
25、c(sizeof(struct book); fscanf(fp,"%d%s%s%s%s%d%fn",&p1->num,p1->bname,p1->wname,p1->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 prin
26、t_book(struct book *head)struct book *ptr;if(head=NULL)printf("n没有信息!n");return;printf(" 图书信息列表如下n");printf(" =n");printf(" 编号 图书名 作者名 类别 出版时间 价格n");for(ptr=head;ptr;ptr=ptr->next)printf(" %d %s %s %s %s %d %.2fn",ptr->num,ptr->bname,ptr->
27、;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) /对
28、于文件中只有一组数据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->
29、num!=a&&p1->next!=NULL) p2=p1; p1=p1->next; if(p1->next=NULL) if(p1->num=a) p2->next=NULL; printf("是否确定从文件中彻底删除该图书?(y/n)n"); getchar(); scanf("%c",&b); switch(b) case 'n': break; case 'y': fprint(head); printf("删除成功!n"); getcha
30、r(); 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("删除成功!n"); getchar(); break; else
31、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("
32、 * 1-按图书编号查询 2-按图书名查询 *n");printf(" * 3-按图书类别查询 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;ca
33、se 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!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
34、->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->num,p->bname,p->wname,p->press,p->sort,p->time,p
35、->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(" 你所
36、查询的图书信息如下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");
37、/按作者名查询图书信息void wname_chaxun(struct book *head)char a50;int flag=0;struct book *p; printf("请选择您要查询的图书作者名:");gets(a);p=head; while(p!=NULL)if(strcmp(p->wname,a)=0)flag=1;break;p=p->next; if(flag=0)printf("没有找到该图书名的图书!n");else printf(" 你所查询的图书信息如下n");printf(" =
38、n");printf(" * 编号 图书名 作者名 类别 出版时间 价格 *n"); while(p!=NULL)if(strcmp(p->wname,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);flag=1; p=p->next; printf(" =n");/按图书类别查询图书信息void sort_chax
39、un(struct book *head)char a50;int flag=0;struct book *p; printf("请选择您要查询的图书类别:");gets(a);p=head; while(p!=NULL)if(strcmp(p->sort,a)=0)flag=1;break;p=p->next; if(flag=0)printf("没有找到该图书名的图书!n");else printf(" 你所查询的图书信息如下n");printf(" =n");printf(" * 编号
40、图书名 作者名 类别 出版时间 价格 *n"); while(p!=NULL)if(strcmp(p->sort,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);flag=1; p=p->next; printf(" =n");/按图书出版时间查询图书信息void time_chaxun(struct book *head)int a,
41、flag=0;struct book *p; printf("请选择您要查询的图书出版时间:");scanf("%d",&a); getchar();p=head; while(p!=NULL)if(p->time=a)flag=1;break;p=p->next; if(flag=0)printf("没有找到该图书名的图书!n");else printf(" 你所查询的图书信息如下n");printf(" =n");printf(" * 编号 图书名 作者名 类别
42、 出版时间 价格 *n"); while(p!=NULL)if(p->time=a)printf(" * %d %s %s %s %s %d %.2f *n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1; p=p->next; printf(" =n");/修改图书信息void xiugai(struct book *head)int a,b;char c;struct book *p;printf(&
43、quot;请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL)if(p->num=a)break;p=p->next;if(p=NULL)printf("没有找到该编号的图书!n");getchar();elseprintf(" =n");printf(" * 1-编号 2-图书名 3-作者名 *n");printf(" * 4- 5-类别 6-出版时间 *n");printf(" * 7-价格 8-修改全部 0-放弃修改 *n");printf(" =n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b)case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!n");getchar();break;c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026中国人民大学党委宣传部招聘2人考试备考题库及答案解析
- 2026年黑龙江司法警官职业学院单招职业技能考试题库附答案详细解析
- 2026年镇江扬中市事业单位集中公开招聘工作人员36人笔试模拟试题及答案解析
- 2026年滁州城市职业学院单招职业适应性测试题库有答案详细解析
- 2026天津城建大学委托某劳务派遣公司招聘劳务派遣人员(社会化工会工作者岗位)1人笔试模拟试题及答案解析
- 2026浙江事业单位统考温州市文成县招聘63人笔试模拟试题及答案解析
- 2206北京大学未来技术学院招聘劳动合同制人员1人笔试模拟试题及答案解析
- 2026天津现代职业技术学院招聘(含博士)3人笔试参考题库及答案解析
- 湖北省武汉市新观察2026届统一检测试题英语试题含解析
- 山西省大同市云冈区2025-2026学年初三第一次调研考试(物理试题理)试卷含解析
- 冀教版五年级下册小学英语全册单元测试卷(含听力音频文件)
- 琉璃瓦施工合同协议书
- 《动物营养学》全套教学课件
- 车间物料流转管理制度
- 《人工智能安全导论》 课件 第五章 人工智能技术在网络入侵检测领域
- 《康复评定技术》课件-第二章 人体形态与反射评定技术
- 开展课外读物负面清单管理的具体实施举措方案
- 北师大版二年级数学下册全册10套试卷(附答案)
- 西方哲学史复习笔记
- 集团公司战略协议管理办法
- 非煤地下矿山风险辨识与评估
评论
0/150
提交评论