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

下载本文档

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

文档简介

#include #include #include #define N 15/编号位数#define M 15 /名称字节数#define K 15 /作者字节数#define F 15 /出版社字节数#define O 2 void printf_(struct book *p0); /输出单本的图书数据 struct book * scanf1_();/接收单本的图书数据,返回指针,struct book * scanf_();/得到图书的数据,并放入到链表中struct book *num_paixu(struct book *head);/用链表给学生排序void print_(struct book *head);/输出链表中的图书信息void chaxun(struct book *head); /查询图书的信息,并把图书的数据输出struct book * charu(struct book *head);/将图书的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。struct book * shanchu(struct book *head);/删除数据void xiugai(struct book *head);/修改图书的信息。void fprint_(struct book *head);/把数据写入到文件int to_ji(struct book *head);/统计图书的总本数struct book * jc_paixu(struct book *head);/按价格和出版时间排序struct book * load(); /从文件读取图书信息/建立图书结构体struct bookchar numN;char nameM;char zuozheK;char chubanF;int jcO;struct book *next;void main() int i=0,g=0;char mm7,ch; char c7;FILE *fp;int n,x=1,k=0;float aO=0;struct book *head=NULL;if(fp=fopen(密码(勿删,否则出错!).txt,r)=NULL)printf(密码载入失败!n);exit(0);for(i=0;i6;i+)mmi=fgetc(fp);mm6=0;printf(请输入密码n);loop: for (i=0;inext=NULL) printf(请先录入图书的数据!); getchar(); break; else fprint_(head);break; case 3: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else print_(head);break; case 4: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else head=jc_paixu(head); break; case 5: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else k=to_ji(head); printf(总共有%3d 本书,k); getchar(); break; case 6: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else chaxun(head); getchar(); break; case 7: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else head=charu(head);break; case 8: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else head=shanchu(head); break; case 9: if(head=NULL|head-next=NULL) printf(请先录入图书的数据!); getchar(); break; else xiugai(head); break; case 10: head = load(); if(head=NULL) printf(请先录入图书的数据!); getchar(); break; else break; case 11: if(fp=fopen(密码(勿删,否则出错!).txt,w)=NULL) printf(文件载入失败!n); exit(0); printf(请输入6位新密码!n); for(i=0;inum);printf(书名: );puts(p0-name);printf(作者: );puts(p0-zuozhe);printf(出版社: );puts(p0-chuban);printf(价格: );printf(%-8dn,p0-jc0); printf(出版时间:);printf(%-8d,p0-jc1);printf(n);/接收单本的图书数据,返回指针,struct book * scanf1_()struct book *p0;p0=(struct book *)malloc(sizeof(struct book);printf(请输入图书的编号:);gets(p0-num);printf(请输入图书的名称:);gets(p0-name);printf(请输入图书的作者:);gets(p0-zuozhe);printf(请输入图书的出版社:);gets(p0-chuban);printf(请输入图书的价格:);scanf(%d,&p0-jc0); printf(请输入图书的出版时间:);scanf(%d,&p0-jc1);getchar();return p0;/得到图书的数据,并放入到链表中struct book * scanf_()struct book *p1,*p2,*head;int n=0;printf(注意:当图书编号为 0 时输入结束nn);p1=(struct book *)malloc(sizeof(struct book); /*得到图书信息*/head=p2=p1;doprintf(请输入图书的编号:);gets(p1-num);if(strcmp(p1-num,0)=0)goto endd;printf(请输入图书的名称:);gets(p1-name);printf(请输入图书的作者:);gets(p1-zuozhe);printf(请输入图书的出版社:);gets(p1-chuban);printf(请输入图书的价格:);scanf(%d,&p1-jc0);printf(请输入图书的出版时间:);scanf(%d,&p1-jc1);getchar();printf(n);p1=(struct book *)malloc(sizeof(struct book);p2-next=p1;p2=p1;n+;while(1);endd:p1-next=NULL;printf(信息输入完毕!n);getchar();/*图书的数据被放在链表中*/return head;/*输出链表中的图书信息*/void print_(struct book *head)struct book *p;printf(*n);printf(*|编号t|书名t|作者t|出版社t|价格t|出版时间t| *n);printf(*n);/打印表格域 p=head;doprintf(*|%st|%st|%st|%st|%dt|%dt| *n,p-num,p-name,p-zuozhe,p-chuban,p-jc0,p-jc1); printf(*n);/打印表格域p=p-next;while(p!=NULL);getchar();/*用链表给图书排序*/struct book *num_paixu(struct book *head)struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;int x=1;for(p1=head;p1-next!=NULL;p4=p1,p1=p1-next)p3=p1;for(p2=p1-next,p5=p7=p2;p2!=NULL;p7=p2,p2=p2-next)if(strcmp(p3-num,p2-num)0)p3=p2;p5=p7;if(p3!=p1)if(x&p1=head)p6=p1-next;p1-next=p3-next;p3-next=p6;p5-next=p1;head=p3;p1=p3;x=0;elsep6=p1-next;p1-next=p3-next;p3-next=p6;p4-next=p3;p5-next=p1;p1=p3;printf(排序成功!n);return head;/查询图书的信息,并把图书的数据输出void chaxun(struct book *head) int k;char aN;struct book *p1; printf(*n);printf(* 0-放弃查询 *n);printf(* 1-按编号查询 *n);printf(* 2-按书名查询 *n);printf(* 3-按作者查询 *n);printf(* 4-按出版社查询 *n);printf(*n);scanf(%d,&k);getchar();switch(k) case 0:break;case 1:printf(请输入要查询的图书编号:);gets(a); p1=head; while(p1-next!=NULL)if(strcmp(p1-num,a)=0)break;p1=p1-next;if(p1-next=NULL)printf(没有找到编号为 %s 的图书!n,a);elseprintf(要查询的图书信息如下:nn);printf_(p1);break;case 2:printf(请输入要查询的书名:);gets(a); p1=head; while(p1-next!=NULL)if(strcmp(p1-name,a)=0)break;p1=p1-next;if(p1-next=NULL)printf(没有找到名称为 %s 的图书!n,a);elseprintf(要查询的图书信息如下:nn);printf_(p1);break;case 3:printf(请输入要查询的作者:);gets(a); p1=head; while(p1-next!=NULL)if(strcmp(p1-zuozhe,a)=0)break;p1=p1-next;if(p1-next=NULL)printf(没有找到作者为 %s 的图书!n,a);elseprintf(要查询的图书信息如下:nn);printf_(p1);break;case 4:printf(请输入要查询的出版社:);gets(a); p1=head; while(p1-next!=NULL)if(strcmp(p1-chuban,a)=0)break;p1=p1-next;if(p1-next=NULL)printf(没有找到出版社为 %s 的图书!n,a);elseprintf(要查询的图书信息如下:nn);printf_(p1);break;default:printf(您的输入有误!);getchar();break;/将图书的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。struct book * charu(struct book *head)struct book *p1,*p2,*p3;p1=scanf1_();p2=head;p3=p2;while(strcmp(p2-num,p1-num)next!=NULL)p3=p2;p2=p2-next;if(p2=head)p1-next=head;head=p1;else p3-next=p1;p1-next=p2;printf(插入成功!n);getchar();return head;/删除数据struct book * shanchu(struct book *head)char aN;struct book *p1,*p2,*p3;printf(请输入要删除的图书的编号:);gets(a);p1=head;p2=p1;while(strcmp(p2-num,a)!=0)&p2-next!=NULL)p3=p2;p2=p2-next;if(p2-next=NULL)printf(没有找到要删除的数据!n);else if(p2=head)head=p2-next;printf(删除成功!n);else p3-next=p2-next;printf(删除成功!n);getchar();return head;/修改图书的信息。void xiugai(struct book *head)char aN;struct book *p1;int i,k;printf(输入要修改的图书的编号);gets(a);p1=head;while(p1-next!=NULL)if(strcmp(p1-num,a)=0)break;p1=p1-next;if(p1-next=NULL)printf(没有要找的图书信息!n);getchar();elseprintf(*n);printf(* 0-放弃修改 *n);printf(* 1-修改编号 *n);printf(* 2-修改书名 *n);printf(* 3-修改作者 *n);printf(* 4-修改出版社 *n);printf(* 5-修改价格或出版时间*n);printf(* 6-修改全部 *n);printf(*n);scanf(%d,&k);getchar();switch(k) case 0:break;case 1: printf(请输入新编号:);gets(p1-num);printf(修改成功!);getchar();break;case 2:printf(请输入新书名:);gets(p1-name);printf(修改成功!);getchar();break;case 3:printf(请输入新作者:);gets(p1-zuozhe);printf(修改成功!);getchar();break;case 4:printf(请输入新出版社:);gets(p1-chuban);printf(修改成功!);getchar();break;case 5:printf(*n);printf(* 0-放弃修改 *n);printf(* 1-修改价格和时间 *n);printf(* 2-修改图书价格 *n);printf(* 3-修改出版时间 *n);printf(*n);scanf(%d,&k);switch(k)case 0:break;case 1:p1-jcO-1=0;printf(请输入价格和出版时间:);for(i=0;ijci);printf(修改成功!);getchar();getchar();break;case 2:printf(请输入新价格:);scanf(%d,&p1-jc0);printf(修改成功!);getchar();break;case 3:printf(请输入新出版时间:);scanf(%d,&p1-jc1);printf(修改成功!);getchar();break;default :printf(您的输入有误!);getchar();break;break;case 6:printf(请输入新的编号:);gets(p1-num);printf(请输入新的书名:);gets(p1-name);printf(请输入新的作者:);gets(p1-zuozhe);p1-jcO-1=0;printf(请输入新的价格:);scanf(%d,&p1-jc0);printf(请输入新的出版时间:); scanf(%d,&p1-jc1);printf(修改成功!);getchar();getchar();break;default:printf(您的输入有误!);getchar();break;/统计图书的总本数int to_ji(struct book *head)int n=0;struct book *p1;for(p1=head;p1-next!=NULL;p1=p1-next)n+;return n+1;/按价格和出版时间排序排序struct book * jc_paixu(struct book *head)struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;int x=1,n,i;char ch;printf(*n);printf(* 0-退出 *n);printf(* 1-按价格排序 *n);printf(* 2-按出版时间排序 *n);printf(* 3-按图书编号排序 *n);printf(*n);scanf(%d,&n);if(n!=0)getchar();switch(n)case 0: break;case 1: i=0;break;case 2: i=1;break;case 3:head=num_paixu(head);printf(是否显示排序结果 Y/N ?);ch=getchar();getchar();if(ch=y|ch=Y)printf(n);print_(head);break;default:printf(输入有误!);getchar();break;if(n0)for(p1=head;p1-next!=NULL;p4=p1,p1=p1-next)p3=p1;for(p2=p1-next,p5=p7=p2;p2!=NULL;p7=p2,p2=p2-next)if(p3-jci-p2-jcinext;p1-next=p3-next;p3-next=p6;p5-next=p1;head=p3;p1=p3;x=0;elsep6=p1-next;p1-next=p3-next;p3-next=p6;p4-next=p3;p5-next=p1;p1=p3;printf(排序成功!

温馨提示

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

评论

0/150

提交评论