I. Purpose
By designing a program of the book management system, we can make full use of the main knowledge points of the course, consolidate the understanding of modular program design and file operation, and improve the software programming ability.
2. Points of knowledge involved
Loops, branching statements, functions, arrays, functions, structs, pointers, linked lists, file read operations, and so on
3. Functional points that the program has achieved (explained in 100-200 words)
(1) The program has the following functions, and the operation flow is shown in the following figure:
Login interface:
Enter the user name (admin) and password (20190611). Only if the user name and password are both correct (the information is stored in the file) can you enter the main menu of the system. Otherwise, you need to re-enter the user name and password.(Entering 3 errors at the same time will exit the program).
Operation functions: Input 1 for book storage, input 2 for modifying information, input 3 for deleting information, input 4 for book query, input 5 for book overview, input 6 for exiting software, input 7 for modifying password;
Modify information: Enter the corresponding book name and number, and then make the corresponding changes.
Delete information: Enter the corresponding number, and then confirm that deletion does not delete.If the number corresponding to the input is incorrect, the main menu can be retrieved and returned, and then the main menu can be returned.
Book query: Input 1 for book name query, input 2 for author query, input 3 for login number query, input 4 for publisher query, input 5 for fuzzy query, the query information matches the existing information into the book overview.Enter 0 to return to the main menu;
Book Overview: You can view all book information that has been entered;
Quit software: Quit book management information system;
_Modify password: Enter the old password first, the old password is correct, and then enter the new password twice in a row (the results are identical). After that, the new password replaces the old password and stores it in the account information file, and then jumps to the login interface to login again.If the old password is incorrect, you can return to the main menu;
(2) Define the following structure types:
user name structure: members are: account, password;
Book Information structure BOOK: members are: number (login number), name (book name), author (author name), type (type), publish (publishing unit), time (publishing time), price (price), num (quantity);
(3) Account information is stored inName.txtFiles, book information records are kept in mybook;
(4) Using the modular programming method, that is, main() displays the main menu, calls related functions to achieve the corresponding functions, and plays a dominant role.
(5) Additional functions:
Users will quit the program if they have repeatedly mistyped their passwords more than three times in a row;
4. Screenshots and descriptions of program operation (each picture is limited to 50 to 100 words)
Login interface:
Enter the user name (admin) and password (20190611). Only if the user name and password are both correct (the information is stored in the file) can you enter the main menu of the system. Otherwise, you need to re-enter the user name and password.(Entering 3 errors at the same time will exit the program).As shown in the diagram:
Operation functions: Input 1 for book storage, input 2 for modifying information, input 3 for deleting information, input 4 for book query, input 5 for book overview, input 6 for exiting software, input 7 for modifying password, as shown in the following figure:
Book warehousing: Enter the information of a book into a binary file type.Save successfully returns to the main menu; press any key to return to the main menu; as shown in the following figure:
Modify information: Enter the corresponding book name and number, and then make the corresponding changes to the book warehousing function.As shown in the following figure:
Delete information: Enter the corresponding number, and then confirm that deletion does not delete.If the number corresponding to the input is incorrect, the main menu can be retrieved and returned, and then the main menu can be returned; as shown in the following figure:
Book query: Input 1 for book name query, input 2 for author query, input 3 for login number query, input 4 for publisher query, input 5 for fuzzy query, the query information matches the existing information into the book overview.Enter 0 to return to the main menu; as shown in the following figure:
Book Overview: You can view all the book information that has been entered; as shown in the following figure:
Exit software: Exit the library management information system.As shown in the following figure:
_Modify password: Enter the old password first, the old password is correct, and then enter the new password twice in a row (the results are identical). After that, the new password replaces the old password and stores it in the account information file, and then jumps to the login interface to login again.If the old password is incorrect, you can return to the main menu; as shown in the following figure:
5. Design ideas (no less than 200 words)
This course design, except for all kinds of idle time, spends about 10 hours in design, 20 hours in programming, 35 hours in input and debugging, and about 30 hours in thinking.
During the debugging process, I also encountered a lot of difficulties, such as failed compilation, no logic errors in the checking process, and after I had no idea what to do, I put the part of code that was in problem into the new source code to test separately. After debugging, I found the problem and corrected it.Compilation passed, program runtime warnings occurred, unable to understand, I also put the part of the code in the new source code to test separately, after debugging, found the problem roughly in the fscanf statement and fprintf statement, and finally through query data found that the original read and write file, fscanf statement and fprintf statement, in the output and input table columns are not usedPlus & sign.The problem has also been solved.
There are also many problems encountered, which are solved by steps like debugging - locking the target - consulting the material.
For my program, I think the function is still perfect.But there are still many places to add, such as adding a list of books to borrow, not registering after expiration, etc. Code can also be simplified, and more general functions can be designed, such as building a chain table function, deleting data functions, and so on.With the experience of this design, I believe I can do better next time.
Harvest:
Through this course design, I understand how to complete a good program.
First, there must be a clear demand analysis, only in this way can we better improve the procedures;
Secondly, a clear and reasonable framework structure is needed to make the functions run smoothly.
Third, for each function, we need to design accurate, simple and user-friendly algorithms and operation logic so that each function can bring users a better experience.
Fourth, when writing code, you should have clear ideas, clear text, multiple notes, drawing flowcharts, and writing documents, so as to make your ideas clearer and avoid errors more effectively.
Fifth, the debugging process is one of the most important steps to achieve the whole program. Problems encountered in debugging can not be solved. You should execute them in your own code, exclude them one by one until the target is locked. In addition, the debugging function on the compiler is also very useful. You can quickly find the crux of the problem by executing statements one by one and changing a certain value.
In addition, my knowledge of C language is more in-depth and solid, and my knowledge of chain tables, pointers and files is more comfortable.After that, I would like to try to actually complete a program to better consolidate my knowledge.
Code:
/*
*/
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>
#include <time.h>
#define N sizeof(struct BOOK)
char c; //Enter any key
struct BOOK //book information
{
char number[10]; //Login Number char name[10]; //Title char author[10]; //Author Name char type[10]; //type char publish[10]; //Publishing Units char time[8]; //Publication Time float price; //Price int num; //Number int x; struct BOOK *next; //Pointer field
};
typedef struct BOOK Book;
typedef Book *book;
void gaimi(); //change password
void login(); //login interface
void HideCursor(); //Hide Cursor
void toxy(int x, int y); //Move the cursor to X,Y coordinates
void over(); //exit
void menu(); //menu
void input_book(); //book warehousing
void save_book(book p); //Save book information in a file
void find_book(); //book inquiry
void print_book(); //book overview
void del_book(); //delete books
void amend_book(); //modify information
book ss();
void find_name_book(); //Query by book name
void find_author_book(); //Query by author
void find_number_book(); //Query by login number
void find_publish_book(); //inquire by publisher
void fuzzy_search(); //fuzzy search
struct user
{//Structures for storing user names
char pwd[20];
}us;
char username[15]="admin", pwd1[100]; //username[15] original account, pwd1 password change comparison
void HideCursor()//Hide Cursor
{
CONSOLE_CURSOR_INFO cursor_info = ;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void toxy(int x, int y)//Move cursor to X,Y coordinates
{
COORD pos = { x , y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void menu()//menu
{
time_t T; //Get system time
struct tm * timenow;
time ( &T );
timenow = localtime ( &T );
do
{
system("cls");
HideCursor(); //hide cursor printf("\n\n"); printf("\t The current system time is: %s",asctime (timenow) ); system("color 3f");//Set a nice color char t; toxy(50,5);//Move the cursor to (50,5) coordinates printf(" Library Management Information System "); toxy(48,8); printf("| 1.Books in warehouse |"); toxy(48,10); printf("| 2.Modify Information |"); toxy(48,12); printf("| 3.Delete Information |"); toxy(48,14); printf("| 4.Book Search |"); toxy(48,16); printf("| 5.Book Overview |"); toxy(48,18); printf("| 6.Exit software |"); toxy(48,20); printf("| 7.Change Password |"); t=getch(); //Non-echo function switch(t) { case '1':input_book();break; case '2':amend_book();break; case '3':del_book();break; case '4':find_book();break; case '5':print_book();break; case '6':over();break; case '7':gaimi();break; default :break; } }while(1);
}
book ss() // Read the contents of the file into the chain table, returning the header address
{
FILE *fp; //field name pointer int n=0; book head=NULL; book p2,p,pr=NULL; fp=fopen("mybook","ab+"); //Open file as read-only if(fp==NULL) { printf("cannot open file\n"); } while(!feof(fp)) //Determines whether the file location flag moves to the end of the file { n++; p=(book)malloc(N); //Request a space from memory fread(p,N,1,fp); //Assign the contents of the file pointed to by fp to p if(n==1) { head=p; p2=p; } else //Create Chain List { pr=p2; p2->next=p; p2=p; } } if(pr!=NULL) pr->next=NULL; else head=NULL; fclose(fp); //Close File return head; //Return Head Pointer
}
void input_book()//book entry
{
do { system("cls"); system("color 3f"); char t; book p; p=(book)malloc(N); //Request Space //Enter book information toxy(48,8); printf("Please enter the book login number(Less than 10 digits): "); scanf("%s",p->number);getchar(); toxy(48,10); printf("Please enter a book name(Less than 10 digits): "); scanf("%s",p->name);getchar(); toxy(48,12); printf("Please enter the author name(Less than 10 digits): "); scanf("%s",p->author);getchar(); toxy(48,14); printf("Please enter a book category(Less than 10 digits): "); scanf("%s",p->type);getchar(); toxy(48,16); printf("Please enter the book publisher(Less than 10 digits): "); scanf("%s",p->publish);getchar(); toxy(48,18); printf("Please enter the book publication time(Less than 8 digits): "); scanf("%s",p->time);getchar(); toxy(48,20); printf("Please enter the book price:"); scanf("%f",&p->price);getchar(); toxy(48,22); printf("Please enter the number of books:"); scanf("%d",&p->num); save_book(p); toxy(48,24); printf("Saving...."); Sleep(500); //Pause for 0.5 seconds system("cls"); toxy(46,8); printf("-------------------------"); toxy(46,9); printf("| |"); toxy(46,10); printf("| Save successfully!Do you want to continue? |"); toxy(46,12); printf("| 1.yes 2.no |"); toxy(46,13); printf("| |"); toxy(46,14); printf("-------------------------"); while(1) //Dead cycle prevents other keys from interfering { t=getch(); if(t=='1') { break; } else if(t=='2') { menu(); } } }while(1);
}
void amend_book()//modify book information
{
do { system("cls"); system("color 3f"); book head,p; int i=11,j=0,x; char ch,t; FILE *fp; //field name pointer char _name[10]; char number[10]; //Login Number char name[10]; //Title char author[10]; //Author Name char type[10]; //type char publish[10]; //Publishing Units char time[8]; //Publication Time float price; //Price int num; //Number head=ss(); p=head; toxy(48,10); printf("Enter the title of the book you want to modify:"); gets(_name); while(p!=NULL) //Initialization p->x is 0 { p->x=0; p=p->next; } p=head; //Repoint p to header toxy(20,5); printf("***********************************************Book Information******************************************************\n"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------\n"); toxy(20,10); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number\n"); toxy(20,15); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&strcmp(p->name,_name)==0) { toxy(20,i); j++; printf("\n%12d:%12s%12s%12s%14s %14s %14s %10.2f%12d\n",j,p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); p->x=j; //Label nodes that meet query criteria i++; } p=p->next; } if(j==0) //If j=0, no previous search cycle is entered, that is, no corresponding information is found { toxy(50,i); printf("\n\t\t\t\t\t\t No corresponding information found!(Press 0 to return and 1 to search again)"); while(1) //Dead cycle is to prevent other key interference except 0 and 1 { ch=getch(); if(ch=='0') { menu();break; } else if(ch=='1') { break; } } if(ch=='1') //If the ch entered equals 1, the loop ends continue; } while(1) { toxy(45,i); printf("\n\t\t\t\t\t\t Enter the number of the book you want to modify:"); scanf("%d",&x);getchar(); if(x>j||x==0) { toxy(45,++i); printf("Input error, please re-enter!"); Sleep(500); } else { break; } } p=head; //Repoint p to header while(p!=NULL&&p->x!=x) //Traversing a list of chains to query eligible nodes { p=p->next; } if(p) //If p is not empty { system("cls"); //Enter information to modify toxy(48,8); printf("Please enter the book login number(Less than 10 digits): "); scanf("%s",number);getchar();strcpy(p->number,number); toxy(48,10); printf("Please enter a book name(Less than 10 digits): "); scanf("%s",name);getchar();strcpy(p->name,name); toxy(48,12); printf("Please enter the author name(Less than 10 digits): "); scanf("%s",author);getchar();strcpy(p->author,author); toxy(48,14); printf("Please enter a book category(Less than 10 digits): "); scanf("%s",type);getchar();strcpy(p->type,type); toxy(48,16); printf("Please enter the book publisher(Less than 10 digits): "); scanf("%s",publish);getchar();strcpy(p->publish,publish); toxy(48,18); printf("Please enter the book publication time(Less than 8 digits): "); scanf("%s",time);getchar();strcpy(p->time,time); toxy(48,20); printf("Please enter the book price:"); scanf("%f",&price);getchar();p->price=price; toxy(48,22); printf("Please enter the number of books:"); scanf("%d",&num);getchar();p->num=num; } system("color 3f"); toxy(46,8); printf("-------------------------\n"); toxy(46,9); printf("| |"); toxy(46,10); printf("| Confirm the changes? |\n"); toxy(46,12); printf("| 1.yes 2.no |\n"); toxy(46,13); printf("| |\n"); toxy(46,14); printf("-------------------------\n"); while(1) //Use Dead Cycle to Prevent Other Keys from Disturbing { t=getch(); if(t=='1') { break; } else if(t=='2') { menu(); } } system("cls"); toxy(46,10); printf("Modifying, please wait...."); fp=fopen("mybook","wb"); //Open a binary file named mybook in a write-only manner, emptying the contents while opening it if(fp==NULL) { printf("cannot open file"); } if(fwrite(head,N,1,fp)!=1) //Write the head er to the file that fp points to { printf("write error!"); } fclose(fp); //Close File if(head!=NULL) //If the head er is not empty { p=head->next; //Let p point to the second node fp=fopen("mybook","ab"); //Open file by append if(fp==NULL) { printf("cannot open file"); } while(p!=NULL) { if(fwrite(p,N,1,fp)!=1)//Write p to the file that fp points to { printf("write error!"); } p=p->next; } fclose(fp); //Close File } Sleep(500); //Pause for 0.5 seconds system("cls"); toxy(46,10); printf("Successfully modified!Automatically returning to main menu...."); Sleep(500); break; }while(1);
}
void del_book()//delete information
{
do { system("cls"); system("color 3f"); FILE *fp; book head,p,pre=NULL; int j=0,x,i=11; char name[10]; char t,c,ch; head=ss(); //Call the function to return the header address toxy(48,10); printf("Enter the title of the book you want to delete:"); scanf("%s",name); p=head; while(p!=NULL) { p->x=0; p=p->next; } p=head; toxy(20,5); printf("***********************************************Book Information******************************************************"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number"); toxy(20,10); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&strcmp(p->name,name)==0) { toxy(20,i); j++; printf("%d:%s%14s%14s%14s %14s %18s %.2f%12d\n",j,p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); p->x=j; i++; } p=p->next; } if(j==0) //If j=0, no previous search cycle is entered, that is, no corresponding information is found { toxy(50,i); printf("No corresponding information found!(Press 0 to return and 1 to search again)"); while(1) //Dead cycle is to prevent other key interference except 0 and 1 { ch=getch(); if(ch=='0') { menu();break; } else if(ch=='1') { break; } } if(ch=='1') //If the ch entered equals 1, the loop ends continue; } while(1) { toxy(45,i); printf("Enter the number of the book you want to delete:"); scanf("%d",&x);getchar(); if(x>j||x==0) { toxy(45,++i); printf("Input error, please re-enter!"); Sleep(500); } else { break; } } system("color 3f"); toxy(46,8); printf("-------------------------"); toxy(46,9); printf("| |"); toxy(46,10); printf("| Are you sure you want to delete it? |"); toxy(46,12); printf("| 1.yes 2.no |"); toxy(46,13); printf("| |"); toxy(46,14); printf("-------------------------"); while(1) { t=getch(); if(t=='1') { break; } else if(t=='2') { menu(); } } p=head; while(p!=NULL&&p->x!=x) { pre=p; p=p->next; } if(p!=NULL) { if(pre==NULL) { head=head->next; } else { pre->next=p->next; } } free(p); fp=fopen("mybook","wb"); if(fp==NULL) { printf("cannot open file"); } if(fwrite(head,N,1,fp)!=1) { printf("write error!"); } fclose(fp); if(head!=NULL) { p=head->next; fp=fopen("mybook","ab"); if(fp==NULL) { printf("cannot open file"); } while(p!=NULL) { if(fwrite(p,N,1,fp)!=1) { printf("write error!"); } p=p->next; } fclose(fp); } system("cls"); toxy(46,10); printf("Deleting, please wait...."); Sleep(500); system("cls"); toxy(46,8); printf("-------------------------"); toxy(46,9); printf("| |"); toxy(46,10); printf("| Delete successful, continue? |"); toxy(46,12); printf("| 1.yes 2.no |"); toxy(46,13); printf("| |"); toxy(46,14); printf("-------------------------"); while(1) { c=getch(); if(c=='1') { break; } else if(c=='2') { menu(); } } }while(1);
}
void print_book()//book overview
{
system("cls"); system("color 3f"); book head,p; int i=11; int sum=0; head=ss(); toxy(20,5); printf("***********************************************Book Overview******************************************************\n"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------\n"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number\n"); toxy(20,11); printf("-------------------------------------------------------------------------------------------------------------\n"); if(head==NULL) { toxy(45,11); printf("There are no books in the library at the moment.~Go ahead and add some books^_^(Press any key to return)"); getch(); menu(); } p=head; while(p!=NULL) { toxy(20,i); printf("%s%14s%14s%14s %14s %18s %.2f%12d\n",p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); i++; sum+=p->num;//Calculate the total number of books p=p->next; } toxy(48,7); printf("The total number of books is:%d",sum); toxy(45,i); printf("Press any key to return"); getch();//Non-echo function
}
void find_book()//query books
{
do { system("cls"); //Clear screen system("color 3f"); char t; toxy(50,5); printf(" Book Search"); toxy(48,8); printf("| 1.Book Name Query |"); toxy(48,10); printf("| 2.Author Query |"); toxy(48,12); printf("| 3.Logon Number Query |"); toxy(48,14); printf("| 4.Publisher Queries |"); toxy(48,16); printf("| 5.Fuzzy Query |"); toxy(50,18); printf("Press 0 to return to main menu"); t=getch(); switch(t) { case '0':menu();break; case '1':find_name_book();break; case '2':find_author_book();break; case '3':find_number_book();break; case '4':find_publish_book();break; case '5':fuzzy_search();break; default :break; } }while(1);
}
void find_name_book() // query by name
{
system("cls");
system("color 3f");
book head,p; int i=11; head=ss(); char name[10]; toxy(48,8); printf("Enter the title of the book you want to query:"); gets(name); toxy(48,10); printf("Querying...."); Sleep(500); p=head; toxy(20,5); printf("***********************************************Book Overview******************************************************"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number"); toxy(20,10); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&strcmp(p->name,name)==0) { toxy(20,i); printf("%s%14s%14s%14s %14s %18s %.2f%12d\n",p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); i++; } p=p->next; } toxy(45,i); printf("Press any key to return!"); getch(); find_book();
}
void find_author_book() // Query by Author Name
{
system("cls"); system("color 3f"); book head,p; int i=11; head=ss(); char author[10]; toxy(48,8); printf("Enter the author name of the book you want to query:"); gets(author); toxy(48,10); printf("Querying...."); Sleep(500); p=head; toxy(20,5); printf("***********************************************Book Overview******************************************************"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number"); toxy(20,10); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&strcmp(p->author,author)==0) { toxy(20,i); printf("%s%14s%14s%14s %14s %18s %.2f%12d\n",p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); i++; } p=p->next; } toxy(45,i); printf("Press any key to return!"); getch(); find_book();
}
void find_number_book() / /Query by book number
{
system("cls");
system("color 3f");
book head,p; int i=11; head=ss(); char number[10]; toxy(48,8); printf("Please enter the login number of the book you want to query:"); gets(number); toxy(48,10); printf("Querying...."); Sleep(500); p=head; toxy(20,5); printf("***********************************************Book Overview******************************************************"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number"); toxy(20,10); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&strcmp(p->number,number)==0) { toxy(20,i); printf("%s%14s%14s%14s %14s %18s %.2f%12d\n",p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); i++; } p=p->next; } toxy(45,i); printf("Press any key to return!"); getch(); find_book();
}
void find_publish_book()//inquire by publisher
{
system("cls"); system("color 3f"); book head,p; int i=11; head=ss(); char publish[10]; toxy(48,8); printf("Enter the publisher of the book you want to inquire about:"); gets(publish); toxy(48,10); printf("Querying...."); Sleep(500); p=head; toxy(20,5); printf("***********************************************Book Overview******************************************************"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number"); toxy(20,10); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&strcmp(p->publish,publish)==0) { toxy(20,i); printf("%s%14s%14s%14s %14s %18s %.2f%12d\n",p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); i++; } p=p->next; } toxy(45,i); printf("Press any key to return!"); getch(); find_book();
}
void fuzzy_search()//Fuzzy Query
{
system("cls");
system("color 3f");
book head,p; int i=11; head=ss(); char information[10]; toxy(48,8); printf("Please enter the information you want to query the book:"); gets(information); toxy(48,10); printf("Querying...."); Sleep(500); p=head; toxy(20,5); printf("***********************************************Book Overview******************************************************"); toxy(20,8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(20,9); printf("Login Number Title Author Name Book Categories Publishing Units Publication Time Price Number"); toxy(20,10); printf("-------------------------------------------------------------------------------------------------------------"); while(p!=NULL) { if(p!=NULL&&(strcmp(p->name,information)==0||strcmp(p->author,information)==0||strcmp(p->number,information)==0||strcmp(p->publish,information)==0)) { toxy(20,i); printf("%s%14s%14s%14s %14s %18s %.2f%12d\n",p->number,p->name,p->author,p->type,p->publish,p->time,p->price,p->num); i++; } p=p->next; } toxy(45,i); printf("Press any key to return!"); getch(); find_book();
}
void save_book(book p)//Write the contents of P to a file
{
FILE *fp; //field name pointer fp=fopen("mybook","ab"); //Open a binary file named mybook by appending it if(fp==NULL) { printf("cannot open file"); } if(fwrite(p,N,1,fp)!=1) //Save a section of N size that p points to in the file fp points to { printf("write error"); } fclose(fp); //Close File
}
void over()//exit software
{
system("color 3f");
char t; toxy(48,11); printf("-----------------------"); toxy(48,12); printf("| Are you sure you want to quit? |"); toxy(48,14); printf("| 1.Determine 2.cancel |"); toxy(48,15); printf("-----------------------"); while(1) { t=getch(); //Input t switch(t) { case '1': system("cls"); system("color 3f"); toxy(48,10); printf("Exiting safely...."); Sleep(1000); //Pause for 1 second system("cls"); system("color 3f"); toxy(48,10); printf("Software exited safely"); toxy(48,12); printf("Thank you for using!"); toxy(48,14); printf("by-by^_^"); exit(0); break; //Terminate program case '2': menu(); break; //Call the function to enter the menu default :break; } }
}
void login()//login interface
{
int i=0,k=0,j;
FILE *fp; if((fp=fopen("name.txt","r"))==NULL) { strcpy(us.pwd,"20190611"); }//Initial password if file open error fscanf(fp,"%s",us.pwd); char username1[15]; //Define variables to compare with the original password system("color 3f"); //System function, color display color, 3 Lake blue, f is bright white printf("\n\n"); printf("\t System default user name: admin,Password: 20190611\n"); printf("\t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n"); printf("\t┃**********************************************************┃\n"); printf("\t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃\n"); printf("\t┃***┃************************************************┃***┃\n"); printf("\t┃***┃*** ****┃***┃\n"); printf("\t┃***┃*** Welcome to the Library Management Information System ****┃***┃\n"); printf("\t┃***┃*** ****┃***┃\n"); printf("\t┃***┃*** ****┃***┃\n"); printf("\t┃***┃*** Zhang Jintao ****┃***┃\n"); printf("\t┃***┃*** ****┃***┃\n"); printf("\t┃***┃*** 2019 June 11, 2001 ****┃***┃\n"); printf("\t┃***┃*** ****┃***┃\n"); printf("\t┃***┃************************************************┃***┃\n"); printf("\t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃\n"); printf("\t┃**********************************************************┃\n"); printf("\t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n"); for(i=0;i<3;i++){ printf("\n enter one user name:"); gets(username1); printf("\n Please enter a 6-digit password:"); for(j=0;j<100;j++) { pwd1[j]=getch(); if(pwd1[j]=='\r') break; printf("*"); } pwd1[j]='\0'; if((strcmp(username,username1)==0)&&(strcmp(us.pwd,pwd1)==0)) { printf("\n\n You have successfully logged in"); k=1; for(i=0;i<20;i++){ printf("."); Sleep(100); } system("cls");
menu(); //Jump to main interface
break; }
else
printf("\n\n" username or password is invalid, please re-enter: \n");
continue;
}
if(k==0)
Printf ('\n'will exit the program after three consecutive input errors);
Sleep(1000); //Program pause function (in milliseconds), this pause 1000 milliseconds return;//Three consecutive error jumps exit interface
}
void gaimi()//password modification program
{
int j; system("cls"); FILE *fp; if((fp=fopen("name.txt","w"))==NULL){ printf("File open error!");exit(0); } printf("\n Please enter your original password:\n"); fflush(stdin); //Clear Buffer for(j=0;j<100;j++){ us.pwd[j]=getch(); if(us.pwd[j]=='\r') break; printf("*"); } us.pwd[j]='\0'; if((strcmp(us.pwd,pwd1)==0)){ printf("\n Please enter the password you want to modify\n"); for(j=0;j<100;j++){ us.pwd[j]=getch(); if(us.pwd[j]=='\r') break; printf("*"); } us.pwd[j]='\0'; fflush(stdin); //Clear Buffer printf("\n Please confirm your password again\n"); for(j=0;j<100;j++){ pwd1[j]=getch(); if(pwd1[j]=='\r') break; printf("*"); } pwd1[j]='\0'; if((strcmp(us.pwd,pwd1)==0)){ printf("\n\n Password modified successfully, please log in again.\n"); fprintf(fp,"%s",us.pwd); Sleep(2000); system("cls"); login(); } else { printf("\n\n Passwords do not match twice. This service is over!\n\n"); printf("\n\n Press any key to return\n"); c=getch(); system("cls"); menu(); } } else{ printf("\n Wrong password entry!\n\n"); printf("\n\n Press any key to return\n"); c=getch(); system("cls"); menu(); }
}
int main()//main function
{
login();
return 0;
}