Current location - Training Enrollment Network - Books and materials - C language programming book management system?
C language programming book management system?
# include # include # include # include # includestructbook { char number[ 100]; char little[ 100]; char writer[ 100]; char publisher[ 100]; chardate[ 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(); voids can _ book(); intmain(){intc 1=0,c2,C3; intl,x,z; while( 1){ system(" color 2c "); printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n”); Printf(" \ t \ t | *-*- book management system *-* | \ n "); Printf ("\ t \ t * [1] user login * \ n "); Printf ("\ t \ t * [2] Administrator login * \ n "); printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n”); printf(" \ n "); Printf ("Please select your operation:"); scanf("%d ",& ampc 1); System ("CLS"); Break; } if(c 1 = = 1){ while( 1){ system(" color 2c "); printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n”); Printf(" \ t \ t | *-*- book management system *-* | \ n "); Printf ("\ t \ t * [1] query account book * \ n "); Printf ("\ t \ t | [2] Borrowing books | \ n "); Printf ("\ t \ t * [3] Borrowing and returning books * \ n "); Printf ("\ t \ t * [4] Browse book information * \ n "); Printf ("\ t \ t | [5] Exit from the library management system | \ n "); printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n”); printf(" \ n "); Printf ("Please select your operation:"); scanf("%d ",& ampC2); 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"); return0} } } if(c 1 = = 2){ while( 1){ system(" color 2c "); printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n”); Printf(" \ t \ t | *-*- book management system *-* | \ n "); printf(" \ t \ t |[ 1]Add Book | \ n "); Printf ("\ t \ t * [2] Delete books * \ n "); Printf ("\ t \ t | [3] Modify book information | \ n "); Printf ("\ t \ t * [4] Browse book information * \ n "); Printf ("\ t \ t | [5] Exit from the library management system | \ n "); printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n”); printf(" \ n "); Printf ("Please select your operation:"); scanf("%d ",& ampC3); 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"); Return0}}}}/*}/* Query book */Voidsearch _ book () {file * fp; structbooknstructbooknnintl,r; charx,z; Fp=fopen("F:\\ course design \ \ book management system. txt”、“Rb”); while( 1){ l = 0; System ("CLS"); Printf ("Please enter book name:"); scanf("%s ",n . tittle); fflush(stdin); Rewind (FP); while( 1){ fread(& amp; 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 ("No book to query! ! ! \ n \ n "); }else{printf ("The book queried is:"); printf(" \ n "); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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 ("Do you want to continue to query books? [Yes/No (No)]? \ n \ n "); do { x = getche(); }while(x! = ' n ' & amp& ampx! = ' y '); if(x = = ' n ')break; } f close(FP); System ("CLS"); }//Add void Add _ book(){ FILE * FP; structbooknstructbooknncharx,z; intl,r; Fp=fopen("F:\\ course design \ \ book management system. txt”、“a b+”; do { system(" cls "); do { l = 0; printf(" \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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); And (! feof(FP)){ fread(& amp; nn,sizeof(nn), 1,FP); r=strcmp(n.tittle,nn . tittle); if(r = = 0){ l = 1; Printf ("This book already exists, please enter new book information: \ n \ n"); Break; } } } while(l); fwrite(& amp; n,sizeof(n), 1,FP); printf(" \ n "); Printf ("Do you want to continue to enter new book information [y/n] \ n \ n"); do { x = getche(); }while(x! = ' n ' & amp& ampx! = ' y '); } while(x = = ' y '); fclose(FP); System ("CLS"); }//Delete the book void delete _ book () {file * fp, * fp1; charx,z; structbooknstructbooknnintl,r; Fp=fopen("F:\\ course design \ \ book management system. txt”、“a b+”; while( 1){ l = 0; System ("CLS"); printf(" \ n "); Printf ("Please enter the name of the book to be deleted: \ n \ n"); fflush(stdin); scanf("%s ",& ampn . tittle); Rewind (FP); while( 1){ fread(& amp; 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 ("Sorry, book not found \ n"); } else { printf(" \ n "); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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 ("Are you sure you want to delete the book information? [Yes (y)/ No (n)] \ n \ n "); do { z = getche(); }while(z! = ' n ' & amp& ampz! = ' y '); if(z = = ' n ')break; Else{fp 1=fopen("F:\\ course design \ \ book management system new.txt ","WB "); Rewind (FP); while( 1){ fread(& amp; nn,sizeof(nn), 1,FP); if(feof(FP))break; r=strcmp(n.tittle,nn . tittle); if(r! = 0)fwrite(& amp; nn,sizeof(nn), 1,FP 1); } f close(FP); fclose(FP 1); Fp=fopen("F:\\ course design \ \ book management system. txt”、“WB”); Fp 1=fopen("F:\\ course design \ \ book management system new.txt ","Rb "); while( 1){ fread(& amp; nn,sizeof(nn), 1,FP 1); if(feof(FP 1))break; fwrite(& amp; nn,sizeof(nn), 1,FP); } f close(FP); fclose(FP 1); } } printf(" \ n "); Printf ("Do you want to continue deleting book information? [Yes (y)/ No (n)] \ n "); do { x = getche(); }while(x! = ' n ' & amp& ampx! = ' y '); if(x = = ' n ')break; } f close(FP); System ("CLS"); }//Modify book information Voidmodify _ book () {file * fp; structbooknstructbooknnintl,r; charx,z; Fp=fopen("F:\\ course design \ \ book management system. txt”、“r b+”; while( 1){ l = 0; printf(" \ n "); System ("CLS"); Printf ("Please enter the name of the book to be modified: \ n \ n"); fflush(stdin); scanf("%s ",& ampn . tittle); System ("CLS"); Rewind (FP); while( 1){ fread(& amp; 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 ("Sorry, no book information found \ n \ n"); } else { printf(" \ n "); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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 ("Please modify the book information in turn \ 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(& amp; n,sizeof(nn), 1,FP); } printf(" \ n "); Printf ("Continue to modify user information [y/n]? \ n \ n "); do { x = getch(); }while(x! = ' n ' & amp& ampx! = ' y '); if(x = = ' n ')break; } f close(FP); System ("CLS"); }//Borrow a book Voidborrow _ book () {file * fp; structbooknstructbooknncharx,z; intl,r; Fp=fopen("F:\\ course design \ \ book management system. txt”、“r b+”; while( 1){ l = 0; System ("CLS"); printf(" \ n "); Printf ("Please enter the name of the book to borrow: \ n"); fflush(stdin); scanf("%s ",& ampn . tittle); Rewind (FP); while( 1){ fread(& amp; 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 ("Sorry, I can't find the book. \ n "); } else { printf(" \ n "); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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 ("Please enter the book information and modify the status in the library and the borrower information"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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(& amp; n,sizeof(nn), 1,FP); } printf(" \ n "); Printf ("Do you want to keep borrowing books? [Yes (y)/ No (n)] \ n \ n "); do { x = getch(); }while(x! = ' n ' & amp& ampx! = ' y '); if(x = = ' n ')break; } f close(FP); System ("CLS"); }//Returns book void Return _ book(){ FILE * FP;; structbooknstructbooknncharx,z; intl,r; Fp=fopen("F:\\ course design \ \ book management system. txt”、“r b+”; while( 1){ l = 0; System ("CLS"); printf(" \ n "); Printf ("Please enter the name of the book to be returned: \ n"); fflush(stdin); scanf("%s ",& ampn . tittle); Rewind (FP); while( 1){ fread(& amp; 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 ("Sorry, I can't find the book. \ n "); } else { printf(" \ n "); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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 ("Please enter the book information and modify the status in the library \ n \ n"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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(& amp; n,sizeof(nn), 1,FP); } printf(" \ n "); Printf ("Do you want to return the book? [Yes (y)/ No (n)] \ n "); do { x = getche(); }while(x! = ' n ' & amp& ampx! = ' y '); if(x = = ' n ')break; } f close(FP); System ("CLS"); }//Browse voids can _ book(){ FILE * FP; charx,z; Structurbooknfp = fopen ("f: \ \ course design \ \ book management system. txt”、“Rb”); Rewind (FP); System ("CLS"); while( 1){ fread(& amp; n,sizeof(n), 1,FP); if(feof(FP))break; else { printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf ("No. Title, author, publishing time, price, borrower \ 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 ("Please enter to return to the main menu"); do { x = getche(); }while(x! = ' \ r '); if(x = = ' \ r '){ fclose(FP); System ("CLS"); }}