commit ed8141111c8b3c2a6833885d70c08e1dceb2e397 Author: 孙思清 <18408000839@stu.hut.edu.cn> Date: Tue Jan 8 18:53:57 2019 +0800 first commit diff --git a/图书管理系统.cpp b/图书管理系统.cpp new file mode 100644 index 0000000..c326430 --- /dev/null +++ b/图书管理系统.cpp @@ -0,0 +1,724 @@ +#include +#include +#include +int prince=10; +int time=3; +struct book_class +{ + char num[10]; // + char name[10]; // + char author[10]; // + int Price; // +}; +struct book +{ + char num[10]; // ıһ + char name[10] ; // һ + int price; //۸ ļ۸һ +}; +struct person +{ + char number[10] ; //֤ һ + char name [10]; // + char password[10]; // + char class_[15]; //༶ + char num[10]; //ѧţ +}; +void register_m() //Աע +{ + struct person p1; + FILE *fp; + int flag=1,x; + while(flag==1){ + system("cls"); + if((fp=fopen("ԱϢ.txt","a"))==NULL) + { + printf("ļ򿪴!\n"); + exit (0); + } + printf("û:\n"); + scanf("\n%s",p1.number); + fprintf(fp,"\n%s ",p1.number); + printf(":\n"); + scanf(" %s",p1.password); + fprintf(fp,"%s ",p1.password); + printf(":\n"); + scanf(" %s",p1.name); + fprintf(fp,"%s ",p1.name); + printf("༶:\n"); + scanf(" %s",p1.class_); + fprintf(fp,"%s ",p1.class_); + printf("ѧ:\n"); + scanf(" %s",p1.num); + fprintf(fp,"%s ",p1.num); + if(fclose(fp)) + { + printf("ļ޷ر!\n"); + exit (0); + } + printf("עɹ!\n"); + printf("1עᣬ0˳\n\n"); + printf("²:"); + scanf("%d",&flag); + } + return ; +} +void register_y() //ûע + { + struct person p1; + FILE *fp; + int flag=1,x; + while(flag==1){ + system("cls"); + if((fp=fopen("ԱϢ.txt","a"))==NULL) + { + printf("ļ򿪴!\n"); + exit (0); + } + printf("û:\n"); + scanf("\n%s",p1.number); + fprintf(fp,"\n%s ",p1.number); + printf(":\n"); + scanf(" %s",p1.password); + fprintf(fp,"%s ",p1.password); + printf(":\n"); + scanf(" %s",p1.name); + fprintf(fp,"%s ",p1.name); + printf("༶:\n"); + scanf(" %s",p1.class_); + fprintf(fp,"%s ",p1.class_); + printf("ѧ:\n"); + scanf(" %s",p1.num); + fprintf(fp,"%s ",p1.num); + if(fclose(fp)) + { + printf("ļ޷ر!\n"); + exit (0); + } + printf("עɹ!\n"); + printf("1עᣬ0˳\n\n"); + printf("²:"); + scanf("%d",&flag); + } + return ; +} //ûע +int cheakUserValid_m(struct person *p1) //û¼ʱǷȷ +{ + FILE *fp; + struct person p2; + char usr[10],usr1[10],pwd[10],pwd1[10]; + int check=0; + strcpy(usr1,p1->number); + strcpy(pwd1,p1->password); + strcat(usr1,pwd1); + if((fp=fopen("ԱϢ.txt","r"))==NULL) + { + printf("ļ򿪴!\n"); + exit (0); + } + while(!feof(fp)) + { + fscanf(fp,"%s%s%s%s%s%d",p2.number,p2.password,p2.name,p2.class_,p2.num); + strcpy(usr,p2.number); + strcpy(pwd,p2.password); + strcat(usr,pwd); + if(strcmp(usr,usr1)==0) + { + check=1;break; + } + } + if(fclose(fp)) + { + printf("ļ޷ر!\n"); + exit (0); + } + return check; +} +void jiashu() //鱾Ϣ +{ + FILE *fp; + struct book_class b1; + int flag=1; + while(flag==1){ + system("cls"); + if ((fp=fopen("book_class.txt","a"))==NULL) + { + printf("ļ򿪴\n"); + exit(0); + } + printf(":\n"); + scanf("\n%s",b1.num); + fprintf(fp,"\n%s ",b1.num); + printf(":\n"); + scanf(" %s",b1.name); + fprintf(fp,"%s ",b1.name); + printf(":\n"); + scanf(" %s",b1.author); + fprintf(fp,"%s ",b1.author); + printf(":\n"); + scanf(" %d",&b1.Price); + fprintf(fp,"%d ",b1.Price); + if(fclose(fp)) + { + printf("ļ޷رգ\n"); + exit(0); + } + printf("밴1ؽ밴0:\n"); + scanf("%d",&flag); + } + return ; +} +void chashu() //鱾Ϣѯ +{ + FILE *fp; + struct book_class b1; + char a[10]; + int temp=0,flag=1; + while(flag==1){ + system("cls"); + printf(":\n"); + scanf("%s",a); + if((fp=fopen("book_class.txt","r"))==NULL) + { + printf("ļ򿪴!\n"); + exit (0); + } + while(!feof(fp)) + { + fscanf(fp,"%s%s%s%%d%",b1.num,b1.name,b1.author,&b1.Price); + if(strcmp(a,b1.name)==0) + { + printf(" ִ Ѿ\n"); + printf("%s %s %s %d\n",b1.num,b1.name,b1.author,b1.Price); + temp=1; + break; + } + } + if(temp==0) + { + printf("޴鼮\n"); + } + if(fclose(fp)) + { + printf("ļ޷ر!\n"); + exit (0); + } + printf("ѯ밴1ؽ밴0:\n"); + scanf("%d",&flag); + } + return ; +} +void shanshu() //鱾Ϣɾ +{ + FILE *fp,*fp1; + struct book_class b1; + char a[10]; + int flag=1,temp=0; + while(flag==1){ + system("cls"); + printf("Ҫɾ:\n"); + scanf("%s",a); + if((fp=fopen("book_class.txt","r"))==NULL) + { + printf("ļ򿪴!\n"); + exit (0); + } + if((fp1=fopen("bbookk.txt","w"))==NULL) + { + printf("ļ򿪴!\n"); + exit (0); + } + do + { + fscanf(fp,"%s%s%s%d",b1.num,b1.name,b1.author,&b1.Price); + if(strcmp(b1.name,a)!=0) + { + fprintf(fp1,"\n%s %s %s %d",b1.num,b1.name,b1.author,b1.Price); + } + else + temp=1; + }while(!feof(fp)); + if(temp==0) + { + printf("޴鼮\n"); + } + else + printf("ɾɹ\n"); + if(fclose(fp)) + { + printf("ļ޷ر!\n"); + exit (0); + } + if(fclose(fp1)) + { + printf("ļ޷ر!\n"); + exit (0); + } + remove("book_class.txt"); + rename("bbookk.txt","book_class.txt"); + printf("ɾ밴1ؽ밴0:\n"); + scanf("%d",&flag); + } + return ; +} +void jieyuegl() //Ĺ +{ + int a; + while(1) + { + system("cls"); + printf("********** Ϲ **********\n"); + printf("\n\n\n"); + printf("********** 1. **********\n"); + printf("********** 2. **********\n"); + printf("********** 3.ɾ **********\n"); + printf("********** 0. **********\n"); + printf("\n\n\n"); + printf("(0-3):"); + scanf("%d",&a); + if(a==0) + break; + switch(a) + { + case 1:jiashu();break; + case 2:chashu();break; + case 3:shanshu();break; + } + } +} +void guandlscreen() //Ա¼ +{ + int x; + while(1) + { + system("cls"); + printf("********** Ա¼ **********\n"); + printf("\n\n\n"); + printf("********** 1.Ϲ **********\n"); + printf("********** 0.˳¼ **********\n"); + printf("\n\n\n"); + printf("(0-1):"); + scanf("%d",&x); + if(x==0) + break; + switch(x) + { + case 1:jieyuegl();break; + } + } + return ; +} +void denglu_m() //Ա¼ +{ + struct person p1; + system("cls"); + printf("û(֤):\n"); + scanf("%s",p1.number); + printf(":\n"); + scanf("%s",p1.password); + if(cheakUserValid_m(&p1)==1) + { + printf("¼ɹ\n"); + guandlscreen(); + } + else + { + printf("\n"); + system("pause"); + } + } +void lend_out(struct person p2,int choice) // +{ + system("cls"); + struct book_class *su; + int i,year,month,day,year1=0,month1=0,day1=0; //ں͹黹 + char name[20]; // + printf("Ҫĵ\n"); + scanf("%s",name); + printf("ڣxxxx xx xx\n"); + scanf("%d%d%d",&year ,&month ,&day); + FILE *fp1,*fp2,*fp3; + if((fp1=fopen("book_class.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp2 = fopen("book_class1.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp3=fopen("bookone.txt","a"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + while(!feof(fp1)) + { + su=(struct book_class *)malloc(sizeof(struct book_class)); + fscanf(fp1,"%s%s%s%d",su->num,su->name,su->author,&su->Price); + if(!strcmp(name,su->name)) + { + //޸ĽϢ + fprintf(fp2,"\n%s %s %s %d",su->num,su->name,su->author,su->Price); + FILE *fp5,*fp6; //ϢдûϢ + switch(choice) + { + case 0: + { + if((fp5=fopen("ʦϢ.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp6=fopen("ʦϢ2.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + case 1: + { + if((fp5=fopen("ѧϢ.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp6=fopen("ѧϢ2.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + } + while(!feof(fp5)) + { +struct person *p3; + p3=(struct person *)malloc(sizeof(struct person)); + fscanf(fp5,"%s%s%s%s%s%d",p3->number,p3->name,p3->password,p3->class_,p3->num); + if(!strcmp(p3->number,p2.number)) + { + fprintf(fp6,"\n%s %s %s %s %s %d",p3->number,p3->name,p3->password,p3->class_,p3->num); + } + else + fprintf(fp6,"\n%s %s %s %s %s %d",p3->number,p3->name,p3->password,p3->class_,p3->num); + } + FILE *FP1,*FP2,*FP3,*FP4,*FP5,*FP6; //ƻȥ + if((FP1=fopen("book_class1.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP2=fopen("book_class.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP3=fopen("bookone1.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP4 = fopen("bookone.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + switch(choice) + { + case 0: + { + if((FP5=fopen("ʦϢ2.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP6=fopen("ʦϢ.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + case 1: + { + if((FP5=fopen("ѧϢ.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP6=fopen("ѧϢ2.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + } + while(1) + { + char ch; + ch=getc(FP1); + if(feof(FP1)) break; + putc(ch,FP2); + } + while(1) + { + char ch; + ch=getc(FP3); + if(feof(FP3)) break; + putc(ch,FP4); + } + while(1) + { + char ch; + ch=getc(FP5); + if(feof(FP5)) break; + putc(ch,FP6); + } + system("pause"); + fclose(FP1); + fclose(FP2); + fclose(FP3); + fclose(FP4); + fclose(FP5); + fclose(FP6); + return ; +} +} +} +void lend_back(struct person p2,int choice) // +{ + system("cls"); + struct book_class *su; + int i,year,month,day; //黹 + char name[20]; // + printf("\t\tҪ黹\n"); + scanf("%s",name); + FILE *fp1,*fp2,*fp3,*fp4; + if((fp1=fopen("book_class.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp2 = fopen("book_class1.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + while(!feof(fp1)) + { + su=(struct book_class *)malloc(sizeof(struct book_class)); + fscanf(fp1,"%s%s%s%d",su->num,su->name,su->author,&su->Price); + if(!strcmp(name,su->name)) + { + //޸ĽϢ + fprintf(fp2,"\n%s %s %s %d",su->num,su->name,su->author,su->Price); + if((fp3=fopen("bookone.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp4=fopen("bookone1.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + struct book bacbook; + while(!feof(fp3)) + { + fscanf(fp3,"%s%s%d",bacbook.num,bacbook.name,&bacbook.price); + + if((!strcmp(bacbook.name,name))&&(!strcmp(bacbook.num,p2.number))) + { + printf("ɹ\n"); + system("pause"); + } + else + fprintf(fp4,"\n%s %s %d",bacbook.num,bacbook.name,bacbook.price); + } + fclose(fp3); + fclose(fp4); + } + else + fprintf(fp2,"\n%s %s %s %d",su->num,su->name,su->author,su->Price); + } + fclose(fp1); + fclose(fp2); + FILE *fp5,*fp6; //ϢдûϢ + switch(choice) + { + case 0: + { + if((fp5=fopen("ʦϢ.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp6=fopen("ʦϢ2.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + case 1: + { + if((fp5=fopen("ѧϢ.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((fp6=fopen("ѧϢ2.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + } + while(!feof(fp5)) + { +struct person *p3; + p3=(struct person *)malloc(sizeof(struct person)); + fscanf(fp5,"%s%s%s%s%s",p3->number,p3->name,p3->password,p3->class_,p3->num); + if(!strcmp(p3->number,p2.number)) + { + fprintf(fp6,"\n%s %s %s %s %s",p3->number,p3->name,p3->password,p3->class_,p3->num); + } + else + fprintf(fp6,"\n%s %s %s %s %s",p3->number,p3->name,p3->password,p3->class_,p3->num); + } + FILE *FP1,*FP2,*FP3,*FP4,*FP5,*FP6; //ƻȥ + if((FP1=fopen("book_class1.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP2=fopen("book_class.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP3=fopen("bookone1.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP4 = fopen("bookone.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + switch(choice) + { + case 0: + { + if((FP5=fopen("ʦϢ2.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP6=fopen("ʦϢ.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + case 1: + { + if((FP5=fopen("ѧϢ.txt","r"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + if((FP6=fopen("ѧϢ2.txt","w"))==NULL) + { + printf("ļʧܣ\n"); + exit(0); + } + } + break; + } + while(1) + { + char ch; + ch=getc(FP1); + if(feof(FP1)) break; + putc(ch,FP2); + } + while(1) + { + char ch; + ch=getc(FP3); + if(feof(FP3)) break; + putc(ch,FP4); + } + while(1) + { + char ch; + ch=getc(FP5); + if(feof(FP5)) break; + putc(ch,FP6); + } + system("pause"); + fclose(FP1); + fclose(FP2); + fclose(FP3); + fclose(FP4); + fclose(FP5); + fclose(FP6); + return; +} +void mana(struct person p2,int choice) //ûܽ + {while(1) + { + system("cls"); + 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| (0)ҳ |\n"); + printf("\t\t\t| |\n"); + printf("\t\t\t =======================================================\n"); + int n; + scanf("%d",&n); + if(n==0)break; + switch(n) + { + case 1:lend_out(p2,choice);break; + case 2:lend_back(p2,choice);break; + } + } + } +int main(){ + int x; + while(1) + { + system("cls"); + system("color 2e"); + printf(" ͼϵͳ \n"); + printf("\n\n\n"); + printf(" 1.Ա¼ \n"); + printf(" 2.Աע \n"); + printf(" 3.û¼ \n"); + printf(" 4.ûע \n"); + printf(" 0.˳ϵͳ \n"); + printf("\n\n\n"); + printf("(0-4):"); + scanf("%d",&x); + if(x==0) + break; + switch(x) + { + case 1:denglu_m();break; + case 2:register_m();break; + + case 4:register_y();break; + } + } + } +