#include#include#include#include#includestruct book{char number[100];char tittle[100];char writer[100];char publisher[100];char date[100];char price[100];char status[100];char reader[100];};void search_book();void borrow_book();void return_book();void add_book();void delete_book();void modify_book();void scan_book();int main(){int c1=0,c2,c3;int l,x,z;while(1){system("color 2C");printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");printf("\t\t\t* [1] 用户登录 *\n");printf("\t\t\t* [2] 管理员登录 *\n");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");printf("\n");printf("请选择操作 :");scanf("%d",&c1);system("cls");break;}if(c1==1){while(1){system("color 2C");printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");printf("\t\t\t* [1] 查询图书 *\n");printf("\t\t\t| [2] 借阅图书 |\n");printf("\t\t\t* [3] 借图书 *\n");printf("\t\t\t* [4] 浏览图书信息 *\n");printf("\t\t\t| [5] 退图书管理系统 |\n");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");printf("\n");printf("请选择操作 :");scanf("%d",&c2);getchar();switch(c2){case 1:search_book(); break;case 2:borrow_book(); break;case 3:return_book(); break;case 4:scan_book(); break;case 5:system("cls"); return 0;}}}if(c1==2){while(1){system("color 2C");printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");printf("\t\t\t| [1] 添加图书 |\n");printf("\t\t\t* [2] 删减图书 *\n");printf("\t\t\t| [3] 修改图书信息 |\n");printf("\t\t\t* [4] 浏览图书信息 *\n");printf("\t\t\t| [5] 退图书管理系统 |\n");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");printf("\n");printf("请选择操作 :");scanf("%d",&c3);getchar();switch(c3){case 1:add_book(); break;case 2:delete_book(); break;case 3:modify_book(); break;case 4:scan_book(); break;case 5:system("cls"); return 0;}}}}/*查询图书*/void search_book(){FILE*fp;struct book n;struct book nn;int l,r;char x,z;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");while(1){l=0;system("cls");printf("请输入图书名称:");scanf("%s",n.tittle);fflush(stdin);rewind(fp); while(1) {fread(&nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle );if(r==0){l=1;break;}}if(l==0){printf("没要查询图书\n\n ");}else{printf("查询图书:");printf("\n");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");printf("%s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n\n\n");}printf("否继续查询图书 ? [(y)/否(n)] ? \n\n");do{x=getche();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//添加void add_book() {FILE *fp; struct book n;struct book nn;char x,z; int l,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");do {system("cls");do {l=0;printf("\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");fflush(stdin); scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);system("cls");rewind(fp);while(!feof(fp)) {fread(&nn,sizeof(nn),1,fp); r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;printf(" 该图书已存请输入新图书信息: \n\n");break;}}}while(l);fwrite(&n,sizeof(n),1,fp); printf("\n");printf("否继续输入新图书信息[y/n] \n\n");do{x=getche();}while(x!='n'&&x!='y');}while(x=='y');fclose(fp); system("cls");} //删除图书void delete_book() {FILE *fp,*fp1;char x,z;struct book n;struct book nn;int l,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");while(1){l=0;system("cls");printf("\n");printf("请输入需要删除图书名: \n\n");fflush(stdin); scanf("%s",&n.tittle);rewind(fp); while(1) {fread(&nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("起未找该图书 \n");}else{printf("\n");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n");printf("确认删除图书信息 [(y)/否(n)]\n\n");do{z=getche();}while(z!='n'&&z!='y');if(z=='n')break;else{fp1=fopen("F:\\课程设计\\图书管理系统new.txt","wb"); rewind(fp); while(1){fread(&nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle); if(r!=0) fwrite(&nn,sizeof(nn),1,fp1);}fclose(fp);fclose(fp1);fp=fopen("F:\\课程设计\\图书管理系统.txt","wb"); fp1=fopen("F:\\课程设计\\图书管理系统new.txt","rb");while(1){fread(&nn,sizeof(nn),1,fp1); if(feof(fp1))break;fwrite(&nn,sizeof(nn),1,fp); }fclose(fp);fclose(fp1);}}printf("\n");printf("否继续删除图书信息 [(y)/否(n)] \n");do{x=getche();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//修改图书信息void modify_book(){FILE *fp;struct book n;struct book nn;int l,r;char x,z;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");while(1){l=0;printf("\n");system("cls");printf("请输入需要修改图书名: \n\n");fflush(stdin); scanf("%s",&n.tittle);system("cls");rewind(fp); while(1) {fread(&nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("起未找该图书信息 \n\n");}else{printf("\n");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("请依修改图书信息\n\n\n");fflush(stdin);scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);fseek(fp,sizeof(nn),1); fwrite(&n,sizeof(nn),1,fp);}printf("\n");printf(" 否继续修改用户信息[y/n]? \n\n");do{x=getch();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//借书void borrow_book(){FILE*fp;struct book n;struct book nn;char x,z;int l,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");while(1){l=0;system("cls");printf("\n");printf("请输入需要借阅图书名: \n");fflush(stdin); scanf("%s",&n.tittle);rewind(fp); while(1) {fread(&nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("起未找该图书 \n");}else{ printf("\n");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n");fflush(stdin);printf("请输入图书信息并修改库状态及借阅者信息");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);fseek(fp,sizeof(nn),1); fwrite(&n,sizeof(nn),1,fp);}printf("\n");printf(" 否继续借书 [(y)/否(n)] \n\n");do{x=getch();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp); system("cls");}//书void return_book(){FILE*fp;struct book n;struct book nn;char x,z;int l,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");while(1){l=0;system("cls");printf("\n");printf("请输入需要借图书名: \n");fflush(stdin); scanf("%s",&n.tittle);rewind(fp); while(1) {fread(&nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("起未找该图书 \n");}else{printf("\n");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n");fflush(stdin);printf("请输入图书信息并修改库状态 \n\n");printf("****************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);fseek(fp,-(int)sizeof(nn),1); fwrite(&n,sizeof(nn),1,fp);}printf("\n");printf("否继续书 [(y)/否(n)] \n");do{x=getche();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp); system("cls");}//浏览void scan_book(){FILE*fp;char x,z;struct book n;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");rewind(fp); system("cls");while(1) {fread(&n,sizeof(n),1,fp); if(feof(fp))break;else{printf("********************************************\n");printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n"); printf("\n");printf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);printf("\n");}}printf("\n");printf("主菜单请按车");do{x=getche();}while(x!='\r');if(x=='\r'){fclose(fp);system("cls");}}