1、语言图书借阅管理系统372020年4月19日文档仅供参考,不当之处,请联系改正。#include #include #include #include #define STACK_INIT_SIZE 10 #define OK 1 #define TRUE 1 #define FALSE 0 #define ERROR 0struct student /*定义学生类型,用于存放借出的书籍*/ int carnum; char lendbook10; student1000;struct employ /*定义职工类型*/ int employnum; char employname15; in
2、t employage; char employsex2; char employleve10; long int employtage; employ50;struct book /*定义书的类型*/ int booknum; char bookname10; char bookcreat10; int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/ book1000;struct car /*借书卡的数据类型*/ int carnum; char studentname10; int studentclass; car100;int huanbook() /*还书
3、函数*/ FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/ int i,n; int carnum; char lendbook10; printf(请你输入你的卡号n); scanf(%d,&carnum); fp=fopen(car.txt,r); /*读取卡号记录*/ for(i=0;fread(&cari,sizeof(struct car),1,fp)!=0;i+) /*for循环判断卡号是否存在*/ if(cari.carnum=carnum) /*卡号存在,进入下一循环*/ n=i; fclose(fp); printf(
4、请输入你要还的书的名字n); scanf(%s,lendbook); fp=fopen(record.txt,r); for(i=0;fread(&studenti,sizeof(struct student),1,fp)!=0;i+) /*判断是否借阅了输入的书*/ if(strcmp(studenti.lendbook,lendbook)=0) /*借阅了该书,进入下一循环,否则出错显示*/ fclose(fp); fp=fopen(record.txt,r); fp2=fopen(bookl.txt,w); for(i=0;fread(&studenti,sizeof(struct st
5、udent),1,fp)!=0;i+) if(strcmp(studenti.lendbook,lendbook)=0) continue; /*删除还掉的书的借书记录*/ fwrite(&studenti,sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/ fclose(fp); fclose(fp2); fp=fopen(record.txt,w); fp2=fopen(bookl.txt,r); for(i=0;fread(&studenti,sizeof(struct student),1,fp2)!=0;i+) fwrite(&student
6、i,sizeof(struct student),1,fp); /*将借书记录信息写回*/ fclose(fp); fclose(fp2); fopen(bookl.txt,w); /*清临时文件的记录*/ fclose(fp2); fp=fopen(book.txt,r); fp2=fopen(bookl.txt,w); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/ if(i=n) booki.turefalse=1; fwrite(&booki,sizeof(str
7、uct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/ continue; fwrite(&booki,sizeof(struct book),1,fp2); fclose(fp); fclose(fp2); fp=fopen(book.txt,w); fp2=fopen(bookl.txt,r); for(i=0;fread(&booki,sizeof(struct book),1,fp2)!=0;i+) fwrite(&booki,sizeof(struct book),1,fp); /*将临时文件写回*/ fclose(fp); fclose(fp2); fopen
8、(bookl.txt,w); /*清临时文件*/ fclose(fp2); printf(还书完毕,按任意键返回n); getch(); return 1; printf(你没有借这样的书,任意键返回n); /*出错提示*/ fclose(fp); getch(); return 0; printf(系统没这样的卡,和管理员联系,按任意键返回n); /*出错提示*/ fclose(fp); getch(); int findbook() FILE *fp; char bookname10; int ture,i; fp=fopen(book.txt,r); printf(请输入你要查找的书名n
9、); scanf(%s,bookname); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(strcmp(bookname,booki.bookname)=0) if(booki.turefalse=1) printf(这本书的详细资料是:%d %s %s 此书现在无人借阅n按任意键返回n,booki.booknum,booki.bookname,booki.bookcreat); else printf(这本书已经有人借出n);fclose(fp);return 0; fclose(fp); return FALSE; pr
10、intf(没有你要查询的书籍n); fclose(fp); return FALSE; int findbook1() FILE *fp; char bookcreat10; int ture,i; fp=fopen(book.txt,r); printf(请输入你要查找的作者名n); scanf(%s,bookcreat); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(strcmp(bookcreat,booki.bookcreat)=0) if(booki.turefalse=1) printf(这本书的详细资料是:%d
11、 %s %s 此书现在无人借阅n按任意键返回n,booki.booknum,booki.bookname,booki.bookcreat); else printf(这本书已经有人借出n);fclose(fp);return 0; fclose(fp); return FALSE; printf(没有你要查询的书籍n); fclose(fp); return FALSE; int lendcount() FILE *fp; int i,n=0; fp=fopen(record.txt,r); for(i=0;fread(&studenti,sizeof(struct student),1,fp
12、)!=0;i+) printf(卡号:%d 借出的书籍:%s n,studenti.carnum,studenti.lendbook); n=n+1; fclose(fp); printf(当前共有%d本书借出n,n); printf(按任意键n); getch();return n; int chabook() char ch5; do printf(-欢迎进入图书查询系统!-n); printf( 1:n); printf( 2:n); printf( 0:n); printf(请输入0-2,其它输入非法!n); scanf(%s,&ch5); switch(ch5) case 1:fin
13、dbook();getch();break; case 2:findbook1();getch();break; case 0:break; default:printf(无此操作n);getch();break; while(ch5!=0);return FALSE; void lendbook() FILE *fp,*fp2; int i,n; int carnum; printf(请你输入你的卡号n); scanf(%d,&carnum); fp=fopen(car.txt,r); for(i=0;fread(&cari,sizeof(struct car),1,fp)!=0;i+) i
14、f(cari.carnum=carnum) n=i; fclose(fp); printf(请输入你要借阅的书的名字n); scanf(%s,studentn.lendbook); fp=fopen(book.txt,r); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(strcmp(booki.bookname,studentn.lendbook)=0) if(booki.turefalse=0) printf(对不起,此书有人借出,请借其它书n);fclose(fp);getch();return; else fclose
15、(fp); fp=fopen(record.txt,a+); studentn.carnum=carnum; fwrite(&studentn,sizeof(struct student),1,fp); fclose(fp); fp=fopen(book.txt,r); fp2=fopen(bookl.txt,w); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(strcmp(booki.bookname,studentn.lendbook)=0) booki.turefalse=0; fwrite(&booki,sizeof
16、(struct book),1,fp2); continue; fwrite(&booki,sizeof(struct book),1,fp2); fclose(fp); fclose(fp2); fp=fopen(book.txt,w); fp2=fopen(bookl.txt,r); for(i=0;fread(&booki,sizeof(struct book),1,fp2)!=0;i+) fwrite(&booki,sizeof(struct book),1,fp); fclose(fp); fclose(fp2); fopen(bookl.txt,w); fclose(fp2); p
17、rintf(借书完毕,按任意键返回n); getch(); return; printf(不存在这样的书,任意键返回n); fclose(fp); getch(); return; printf(你的卡号不存在,请申请新卡,按任意键返回n); fclose(fp); getch(); void carcount() FILE *fp; int i,n=0; fp=fopen(car.txt,r); for(i=0;fread(&cari,sizeof(struct car),1,fp)!=0;i+) printf(第%d张卡n,i+1,cari.carnum,cari.studentname,
18、cari.studentclass); n=n+1; fclose(fp); printf(当前共有%d本书n,n); printf(按任意键n); getch(); void delcar() FILE *fp,*fp2; int i; int carnum; char choice; fp=fopen(car.txt,r); fp2=fopen(bookl.txt,w); printf(请输入你要删除的卡号n); printf(如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动n); scanf(%d,&carnum); for(i=0;fread(&cari,size
19、of(struct car),1,fp)!=0;i+) if(cari.carnum!=carnum) fwrite(&cari,sizeof(struct car),1,fp2); fclose(fp); fclose(fp2); printf(是否真的要删除该卡?删除后该书籍的所有信息将无法恢复Y/Nn); scanf(%s,&choice); if(choice=y|choice=Y) fp=fopen(car.txt,w); fp2=fopen(bookl.txt,r); for(i=0;fread(&cari,sizeof(struct car),1,fp2)!=0;i+) fwri
20、te(&cari,sizeof(struct car),1,fp); fclose(fp); fclose(fp2); fp2=fopen(bookl.txt,w); fclose(fp2); printf(按任意键返回n); getch(); return; else printf(按任意键返回n); getch(); return; void addcar() FILE *fp; int i=0; fp=fopen(car.txt,a+); printf(请你输入卡号n); scanf(%d,&cari.carnum); printf(请你输入学生姓名n); scanf(%s,cari.s
21、tudentname); printf(请你输入班级n); scanf(%d,&cari.studentclass); fwrite(&cari,sizeof(struct car),1,fp); fclose(fp); printf(输入完毕,任意键返回n); getch(); void changemploy() FILE *fp,*fp2; char employname10,choice;int i; fp=fopen(employ.txt,r); fp2=fopen(bookl.txt,w); printf(请你输入要修改的职工的名字n); scanf(%s,employname);
22、 for(i=0;fread(&employi,sizeof(struct employ),1,fp)!=0;i+) if(strcmp(employi.employname,employname)=0) printf(你所要修改的职工的资料如下,请选择你要修改的内容n); printf(n,employi.employnum,employi.employname,employi.employage,employi.employsex,employi.employleve,employi.employtage); printf(2:修改职工名n); printf(3:修改职工年龄n); pri
23、ntf(4:修改职工工资n); printf(5:修改职工学历n); printf(请输入1-5:); scanf(%s,&choice); switch(choice) case 1: printf(请输入新的职工号n); scanf(%d,&employi.employnum); fwrite(&employi,sizeof(struct employ),1,fp2); break; case 2: printf(请输入新的职工姓名n); scanf(%s,employi.employname); fwrite(&employi,sizeof(struct employ),1,fp2);
24、break; case 3: printf(请输入新的年龄n); scanf(%d,&employi.employage); fwrite(&employi,sizeof(struct employ),1,fp2); break; case 4: printf(请输入新的职工工资n); scanf(%d,&employi.employtage); fwrite(&employi,sizeof(struct employ),1,fp2); break; case 5: printf(请输入新的职工学历n); scanf(%s,employi.employleve); fwrite(&employ
25、i,sizeof(struct employ),1,fp2); default:printf(没有这样的操作);break; continue; fwrite(&employi,sizeof(struct employ),1,fp2); fclose(fp); fclose(fp2); fp=fopen(employ.txt,w); fp2=fopen(bookl.txt,r); for(i=0;fread(&employi,sizeof(struct employ),1,fp2)!=0;i+) fwrite(&employi,sizeof(struct employ),1,fp); fclo
26、se(fp); fclose(fp2); fp2=fopen(bookl.txt,w); fclose(fp2); printf(按任意键返回n); getchar(); return; int delemploy() FILE *fp,*fp2; int i; char employname10,choice; fp=fopen(employ.txt,r); fp2=fopen(bookl.txt,w); printf(请输入你要删除的职工名n); printf(如果你输入的职工存在,系统自动删除该信息!如果不存在,系统不做任何改动n); scanf(%s,employname); for(
27、i=0;fread(&employi,sizeof(struct employ),1,fp)!=0;i+) if(strcmp(employname,employi.employname)!=0) fwrite(&employi,sizeof(struct employ),1,fp2); fclose(fp); fclose(fp2); printf(是否真的要删除该职工信息?删除后的所有信息将无法恢复Y/Nn); scanf(%s,&choice); if(choice=y|choice=Y) fp=fopen(employ.txt,w); fp2=fopen(bookl.txt,r); f
28、or(i=0;fread(&employi,sizeof(struct employ),1,fp2)!=0;i+) fwrite(&employi,sizeof(struct employ),1,fp); fclose(fp); fclose(fp2); fp2=fopen(bookl.txt,w); fclose(fp2); printf(按任意键返回n); getch(); return TRUE; else printf(按任意键返回n); getch(); return FALSE; void employcount() FILE *fp; int i,n=0; fp=fopen(em
29、ploy.txt,r); for(i=0;fread(&employi,sizeof(struct employ),1,fp)!=0;i+) printf(第%d职工的信息如下:nn,n+1,employi.employnum,employi.employname,employi.employage,employi.employsex,employi.employleve,employi.employtage); n+; fclose(fp); printf(当前共有%d个职工n,n); printf(按任意键返回n); void addemploy() FILE *fp; char choi
30、ce=y; int i=1; fp=fopen(employ.txt,a+); while(choice=y|choice=Y) printf(请你输入职工号码n); scanf(%d,&employi.employnum); printf(请你输入职工名n); scanf(%s,employi.employname); printf(请输入职工年龄n); scanf(%d,&employi.employage); printf(请你输入性别n); scanf(%s,employi.employsex); printf(请你输入职工的学历水平n); scanf(%s,employi.emplo
31、yleve); printf(请输入职工的工资n); scanf(%d,&employi.employtage); fwrite(&employi,sizeof(struct employ),1,fp); printf(是否要输入下个职工信息?n); scanf(%s,&choice); printf(按任意键返回n); fclose(fp); void addbook()FILE *fp;int i=0;char choice=y;fp=fopen(book.txt,a+);while(choice=y|choice=Y) printf(请你输入第%d本书的序号n,i+1); scanf(%
32、d,&booki.booknum); printf(请你输入书名n); scanf(%s,booki.bookname); printf(请你输入书的作者n); scanf(%s,booki.bookcreat); printf(请设为1或0,1代表书还没人借,0表示书已经借出,设其它值,程序运行时无法得出正常结果n); printf(请你设定书的状态n); scanf(%d,&booki.turefalse); fwrite(&booki,sizeof(struct book),1,fp); printf(是否要输入下本书n); scanf(%s,&choice); fclose(fp);
33、void bookcount() FILE *fp; int i,n=0; fp=fopen(book.txt,r); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(booki.booknum!=0&strlen(booki.bookname)!=0&strlen(booki.bookcreat)!=0) printf(第%d本书n,i+1,booki.booknum,booki.bookname,booki.bookcreat,booki.turefalse); n=n+1; fclose(fp); printf(当前共有%
34、d本书n,n); printf(按任意键n); void delbook() FILE *fp,*fp2; int i; char bookname10,choice; fp=fopen(book.txt,r); fp2=fopen(bookl.txt,w); printf(请输入你要删除的书名n); printf(如果你输入的书名存在,系统自动删除该信息!如果不存在,系统不做任何改动n); scanf(%s,bookname); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(strcmp(bookname,booki.boo
35、kname)!=0) fwrite(&booki,sizeof(struct book),1,fp2); fclose(fp); fclose(fp2); printf(是否真的要删除该书籍?删除后该书籍的所有信息将无法恢复Y/Nn); scanf(%s,&choice); if(choice=y|choice=Y) fp=fopen(book.txt,w); fp2=fopen(bookl.txt,r); for(i=0;fread(&booki,sizeof(struct book),1,fp2)!=0;i+) fwrite(&booki,sizeof(struct book),1,fp)
36、; fclose(fp); fclose(fp2); fp2=fopen(bookl.txt,w); fclose(fp2); printf(按任意键返回n); getch(); return; else printf(按任意键返回n); getch(); return; void changebook() FILE *fp,*fp2; char bookname10,choice; int i; fp=fopen(book.txt,r); fp2=fopen(bookl.txt,w); printf(请你输入要修改的书籍的书字n); scanf(%s,bookname); for(i=0;fread(&booki,sizeof(struct book),1,fp)!=0;i+) if(strcmp(booki.bookname,bookname)=0) printf(你所要修改的书的资料如下,请选择你要修改的内容n); printf(序号:%d 书名:%s 作者:%s n,booki.booknum,booki.bookname,booki.bookcreat); printf(1:修改书的序号n);