C语言图书管理系统代码_第1页
C语言图书管理系统代码_第2页
C语言图书管理系统代码_第3页
C语言图书管理系统代码_第4页
C语言图书管理系统代码_第5页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

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

文档简介

#include #include /*清屏函数*/#include #include #include #include typedef int BOOL;typedef struct bookinfo/将bookinfo类型定义为BOOKINFO char number15;/*产品编号*/ char name30;/*产品名称*/ float price;/*单价*/ char auther20;/*作者*/ BOOL isExit;/*存在状态*/ char sort20;/*书籍类别*/char published30;/*出版社*/ int bookcount;/*剩余书籍数量*/BOOKINFO;struct bookinfo book1000;typedef struct student /*借书卡的数据类型*/ int studentnum; /学号int cardnum;/卡号char studentname10;/会员姓名 char studentclass10; /会员班级char lendbook10; int count;/借书数组 最多借书十本char bookname1110;/存放书名student;student card1000;/定义借书卡数组char aa6=,kk6=;/初始化密码void input_newp()/*输入新用户信息*/int i; char choice; FILE *a; student newp;system(cls); while(1) newp.count=0;/初始化计数器for(i=0;i11;i+)/初始化借书名称newp.booknamei0=0;printf(输入学号:);scanf(%d,&newp.studentnum);fflush(stdin);printf(输入卡号:);scanf(%d,&newp.cardnum);fflush(stdin);printf(输入学员姓名:);gets(newp.studentname);fflush(stdin);printf(输入学员班级:);gets(newp.studentclass);fflush(stdin);printf(是否保存该条信息?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y) a=fopen(c:card.txt,ab);fwrite(&newp,sizeof(student),1,a);fclose(a); printf(n该用户已添加到c:card.txt文件中!n); else printf(n改用户资料未保存!n); printf(n是否继续添加用户?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; void input_new()/*输入新进的图书信息*/ char choice; FILE *a; BOOKINFO newbook;system(cls); while(1) fflush(stdin);/清除文件缓冲区printf(输入书籍编号:);gets(newbook.number); printf(输入书籍名称:);gets(); printf(输入书籍单价:);scanf(%f,&newbook.price);while(getchar()!=n); printf(输入书籍的作者:);gets(newbook.auther); printf(输入书籍的出版社:);gets(newbook.published); printf(输入书籍的类别:);gets(newbook.sort); printf(输入书籍的数量:);scanf(%d,&newbook.bookcount); printf(是否保存该条书目?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n) printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y) newbook.isExit=1;/*将图书状态设置成1,表示没有借出*/a=fopen(c:bookinfo.data,ab); fwrite(&newbook,sizeof(BOOKINFO),1,a);fclose(a); printf(n该条书目已添加到c:bookinfo.data文件中!n); else printf(n本条书目未保存!n); printf(n是否继续添加书目?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; void search_according_name()/*根据图书名称显示图书的信息*/ char search20=;/*search用来存放要查询的书名*/ int n; FILE *p; char choice; BOOKINFO bookinfo100; int booknumber=0; system(cls); p=fopen(c:bookinfo.data,rb); while(!feof(p) fflush(stdin);/清除文件缓冲区 fread(&bookinfobooknumber,sizeof(BOOKINFO),1,p); booknumber+; booknumber-;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/ fclose(p); while(1) printf(输入要查询的书本名称:);gets(search);if(booknumber=0)printf(书库中没有任何信息!nn);printf(按任意键回到主菜单!nn);getch();break; /*if结束*/elsefor(n=0;nbooknumber;n+)if(strcmp(,search)=0)printf(该书的详细信息如下:n);printf( 图书信息 n);printf(编号 名称 单价 作者 图书状态 出版社 类别 剩余书籍n);break;for(n=0;n=booknumber)printf(没有查找该书的任何信息!n);printf(nn是否继续查询?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; /*else结束*/ /*while(1)结束*/ void search_according_auther()/*根据图书作者显示图书的信息*/ char search20=;/*search用来存放要查询的作者名*/ int n; FILE *p; char choice; BOOKINFO bookinfo100; int booknumber=0; system(cls); p=fopen(c:bookinfo.data,rb); while(!feof(p)fflush(stdin); /清除文件缓冲区fread(&bookinfobooknumber,sizeof(BOOKINFO),1,p);booknumber+; booknumber-;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/ fclose(p); while(1) printf(输入要查询的作者名称:);gets(search);if(booknumber=0)printf(书库中没有任何信息!nn);printf(按任意键回到主菜单!nn);getch();break; /*if结束*/elsefor(n=0;nbooknumber;n+)if(strcmp(,search)=0)printf(该书的详细信息如下:n);printf( 图书信息 n);printf(编号 名称 单价 作者 图书状态 出版社 类别 剩余书籍n);break;for(n=0;n=booknumber)printf(没有查找该书的任何信息!n);printf(nn是否继续查询?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; /*else结束*/ /*while(1)结束*/ void search_according_sort()/*根据图书类别显示图书的信息*/ char search20=;/*search用来存放要查询的类别*/ int n; FILE *p; char choice; BOOKINFO bookinfo100; int booknumber=0; system(cls); p=fopen(c:bookinfo.data,rb); while(!feof(p)fread(&bookinfobooknumber,sizeof(BOOKINFO),1,p);booknumber+; booknumber-;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/ fclose(p); while(1) fflush(stdin);/清除文件缓冲区printf(输入要查询的类别名称:);gets(search);if(booknumber=0)printf(书库中没有任何信息!nn);printf(按任意键回到主菜单!nn);getch();break; /*if结束*/elsefor(n=0;nbooknumber;n+)if(strcmp(bookinfon.sort,search)=0)printf(该书的详细信息如下:n);printf( 图书信息 n);printf(编号 名称 单价 作者 图书状态 出版社 类别 剩余书籍n);break; for(n=0;n=booknumber)printf(没有查找该书的任何信息!n);printf(nn是否继续查询?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; /*else结束*/ /*while(1)结束*/ void search_according_published()/*根据图书出版社显示图书的信息*/ char search20=;/*search用来存放要查询的出版社*/ int n; FILE *p; char choice; BOOKINFO bookinfo100; int booknumber=0; system(cls); p=fopen(c:bookinfo.data,rb); while(!feof(p)fflush(stdin);/清除文件缓冲区fread(&bookinfobooknumber,sizeof(BOOKINFO),1,p);booknumber+; booknumber-;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/ fclose(p); while(1) printf(输入要查询的出版社名称:);gets(search);if(booknumber=0)printf(书库中没有任何信息!nn);printf(按任意键回到主菜单!nn);getch();break; /*if结束*/elsefor(n=0;nbooknumber;n+)if(strcmp(bookinfon.published,search)=0)printf(该书的详细信息如下:n);printf( 图书信息 n);printf(编号 名称 单价 作者 图书状态 出版社 类别 剩余书籍n);break; for(n=0;n=booknumber)printf(没有查找该书的任何信息!n);printf(nn是否继续查询?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; /*else结束*/ /*while(1)结束*/ void delete_according_name()/*根据图书名称对图书信息进行删除*/ char search20=;/*search用来存放要删除的书名*/ int n,i; FILE *p; char choice; BOOKINFO bookinfo100; int booknumber; system(cls); while(1)fflush(stdin);printf(输入要删除的书本名称:);gets(search);p=fopen(c:bookinfo.data,rb);booknumber=0;while(!feof(p) fread(&bookinfobooknumber,sizeof(BOOKINFO),1,p);booknumber+; booknumber-;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/fclose(p); if(booknumber=0) printf(书库中没有任何信息!nn);printf(按任意键回到主菜单!nn);getch();break; /*if结束*/else for(n=0;n=booknumber)printf(没有查找该书的任何信息!n);elseprintf(是否确认需要删除该条书目?(Y/N);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y) for(i=n;ibooknumber-1;i+)/将后面的数组数据全部前移一个bookinfoi=bookinfoi+1; booknumber-; p=fopen(c:bookinfo.data,wb);for(n=0;nbooknumber;n+)fwrite(&bookinfon,sizeof(BOOKINFO),1,p);fclose(p); printf(删除成功!n);elseprintf(nn该条书目没有被删除!); printf(nn是否继续进行删除操作?(Y/N)n);choice=getch();while(choice!=Y&choice!=y&choice!=N&choice!=n)printf(请输入Y或y或N或nn);choice=getch();if(choice=Y|choice=y)continue;else break; /*else结束*/ /*while(1)结束*/void lendbook()/借书FILE *p,*p2; int i,j,k,n=0,z=0; int cardnum; printf(ntt请你输入你的卡号: ); scanf(%d,&cardnum); p=fopen(c:card.txt,rb); while(!feof(p) fread(&cardn,sizeof(student),1,p);n+; fclose(p); p2=fopen(c:bookinfo.data,rb); while(!feof(p2) fread(&bookz,sizeof(BOOKINFO),1,p2);z+; fclose(p2);for(i=0;in;i+)if(cardi.cardnum=cardnum) /判断卡号是否存在 printf(ntt请输入你要借阅的书的名字: ); scanf(%s,&cardi.lendbook); for(j=0;jz;j+) if(strcmp(,cardi.lendbook)=0)/判断书是否存在 if(bookj.bookcount=0)/判断是否还有库存printf(tt对不起,此书有人借出,请借其他书.按任意键返回.n);getch();return;else if(cardi.count=10)/判断是否借满10本 printf(tt对不起,借书本数已达到上限,按任意键返回.n);getch();return;elsep=fopen(c:card.txt,wb);p2=fopen(c:bookinfo.data,wb);cardi.count+;/借书本书加一bookj.bookcount -;/库存减一for(k=1;k=10;k+)if(cardi.booknamek1!=0)strcpy(cardi.booknamek,cardi.lendbook);/保存所借书的名字if(bookj.bookcount=0)bookj.isExit=0;elsebookj.isExit=1;break;for(i=0;in;i+)fwrite(&cardi,sizeof(student),1,p);for(i=0;iz;i+)fwrite(&booki,sizeof(BOOKINFO),1,p2);printf(tt借书已完成,按任意键返回.n); fclose(p);fclose(p2); getch(); return; printf(ntt很抱歉,不存在这本书,按任意键返回.); fclose(p2); getch(); return; printf(ntt你的卡号不存在,请申请新卡,按任意键返回.); fclose(p); getch(); void returnbook()char bookname100;FILE *p,*p2; int i,j,k,n=0,z=0; int cardnum; printf(ntt请你输入你的卡号: ); scanf(%d,&cardnum); p=fopen(c:card.txt,rb); while(!feof(p)fread(&cardn,sizeof(student),1,p);n+; fclose(p); p2=fopen(c:bookinfo.data,rb); while(!feof(p2) fread(&bookz,sizeof(BOOKINFO),1,p2);z+; fclose(p2);for(i=0;in;i+)if(cardi.cardnum=cardnum) /判断卡号是否存在 printf(ntt请输入你要归还的书的名字: ); scanf(%s,&bookname); for(j=0;jz;j+) if(strcmp(,bookname)=0)/判断是否有这本书 for(k=1;k11;k+)if(strcmp(cardi.booknamek,bookname)=0) p=fopen(c:card.txt,wb);p2=fopen(c:bookinfo.data,wb);cardi.count-;bookj.bookcount +;if(bookj.bookcount=0)bookj.isExit=0;elsebookj.isExit=1;for(k=1;k11;k+)if(strcmp(cardi.booknamek,bookname)=0)/清空还书记录 cardi.booknamek0=0; break;for(i=0;in;i+)fwrite(&cardi,sizeof(student),1,p);for(i=0;iz;i+)fwrite(&booki,sizeof(BOOKINFO),1,p2);printf(tt还书已完成,按任意键返回.n); fclose(p);fclose(p2); getch(); return; elseprintf(tt你没借这本书,按任意键返回.n);return; printf(ntt很抱歉,不存在这本书,按任意键返回.); fclose(p2); getch(); return; printf(ntt你的卡号不存在,请申请新卡,按任意键返回.); fclose(p); getch(); void displayuser()/显示所有用户信息 FILE *p; int n,k; n=0; system(cls); p=fopen(c:card.txt,r); while(!feof(p) fread(&cardn,sizeof(student),1,p);n+; fclose(p); if(n=0) printf(没有任何用户信息!nn); else k=0;printf( 用户信息如下n);printf( 用户信息 n); printf(学号 卡号 姓名 班级 所借书本数n); while(kn) if(cardk.studentclass0!=0) /屏蔽空信息printf(%d %d %s %s %d n, cardk.studentnum,cardk.cardnum,cardk.studentname, cardk.studentclass,cardk.count ); k+; printf(nn按任意键回到主菜单!n); getch(); void displaylend()/显示所有借的书 FILE *p; int n,i,j;int cardnum; n=0; system(cls); p=fopen(c:card.txt,r); while(!feof(p) fread(&cardn,sizeof(student),1,p);n+; fclose(p); if(n=0) printf(没有任何用户信息!nn); else printf(ntt请你输入你的卡号: ); scanf(%d,&cardnum); for(i=0;in;i+)if(cardi.cardnum=cardnum) /判断卡号是否存在printf(ntt卡号所借书本如下:n); for(j=1;j11;j+)if(cardi.booknamej0!=0)puts(cardi.booknamej);printf(n);printf(nn

温馨提示

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

评论

0/150

提交评论