web123456

Library Management System [C++]

//Author: Zijin JDD //Time: January 2022 #include <> #include <fstream> #include<iomanip> #include <iostream> #include<> using namespace std; class Reader //Category that stores reader information { public: char ReaderName[50]; //Reader's name char Password[50]; //password char book1[30], book2[30]; //Each person borrows up to two books, you can increase or decrease the limit as needed, and the book stores the ISBN number int y_n; //Record the number of books borrowed, 0 is not borrowed, 1 is borrowed one, 2 is borrowed two books to borrow two Reader *next; //Pointer to the next node }; /***Reader List****/ class ReaderList { //Indicate how many nodes in the linked list public: static Reader * point, *head_point; //Define two Rreader pointers, head_point is the head pointer, point is the active pointer static int o; ReaderList() //Constructor, initialize pointer { head_point = new Reader[sizeof(Reader)]; point = new Reader[sizeof(Reader)]; strcpy(head_point->ReaderName,"0"); head_point->next = NULL; point->next = NULL; o = 0;//Number of readers } static void save_readerfile() //Storage the file, it exists in the linked list { string r1,r2,r3,r4; fstream file; Reader *p; p= new Reader[sizeof(Reader)]; file.open("library//",ios::in | ios::out); if(!file) { cout<<" not open file"<<endl; } getline(file,r1,','); strcpy(p->ReaderName,&r1[0]); strcpy(head_point->ReaderName,&r1[0]); getline(file,r2,','); strcpy(p->Password,&r2[0]); strcpy(head_point->Password,&r2[0]); getline(file,r3,','); strcpy(p->book1,&r3[0]); strcpy(head_point->book1,&r3[0]); getline(file,r4,'\n'); strcpy(p->book2,&r4[0]); strcpy(head_point->book2,&r4[0]); point =head_point; while(!file.eof()) { p= new Reader[sizeof(Reader)]; getline(file,r1,','); if(r1=="")//Enhance the robustness. If the file is wrapped, the last behavior is empty. If it is not added, the last node will be incorrect. { break; } strcpy(p->ReaderName,&r1[0]); getline(file,r2,','); strcpy(p->Password,&r2[0]); getline(file,r3,','); strcpy(p->book1,&r3[0]); getline(file,r4,'\n'); strcpy(p->book2,&r4[0]); p->next=NULL; point->next = p; point = p; o++; } file.close(); delete p; } static void load_readerfile() //Upload file { Reader *q; q = head_point; fstream file; file.open("library//",ios::in | ios::out|ios::trunc); if(!file) { cout<<" not open file"<<endl; } while(q!=NULL) { file<<q->ReaderName<<","<<q->Password<<","<<q->book1<<","<<q->book2<<endl; q = q->next ; } file.close(); } static Reader* reader_register() //Reader registration { string n1,n2; Reader *nw; nw = new Reader[sizeof(Reader)]; cout<<"Name (can't exceed 50 characters):"<<endl; cin >>setw(50)>>n1; //Set the name length cannot exceed 50 cout<<"password:"<<endl; cout<<"Password (can't exceed 50 characters):"<<endl; //Set the password length cannot exceed 50 cin >> n2; strcpy(nw->ReaderName,&n1[0]); strcpy(nw->Password,&n2[0]); strcpy(nw->book1," "); strcpy(nw->book2," "); nw->next = NULL; return nw; } static void Add_Point(Reader * p) //Add new node to link table { save_readerfile(); if(head_point==NULL) { head_point=p; } else { point=head_point; while(point->next!=NULL) { point=point->next; } point->next=p; } Reader *q; string r1,p1,b1,b2; q = head_point; fstream file; file.open("library//",ios::in | ios::out); if(!file) { cout<<" not open file"<<endl; } while(q!=NULL) { file<<q->ReaderName<<","<<q->Password<<","<<q->book1<<","<<q->book2<<endl; // cout<<q->ReaderName<<","<<q->Password<<","<<q->book1<<","<<q->book2<<endl; q = q->next ; } file.close(); } static Reader* reader_land() //Reader login { string readername,readerpass; cout<<"Please enter your name:"<<endl; cin >> readername; point=head_point->next; while(point!=NULL) { if(strcmp(point->ReaderName,&readername[0])==0)//Find users { cout<<"Please enter your password:"; cin>> readerpass; if(strcmp(point->Password,&readerpass[0])==0)// Verify password { cout<<"Login successfully!"<<endl; return point;//Return to user pointer } else { cout<<"Error password!"<<endl; return NULL;//Return empty } } point=point->next;//Next } if(point==NULL) { cout<<"This user does not exist! You can register first and try ^_^"<<endl; } return NULL; } static void show_OneReader(Reader *p) //Show a reader's information { if(p==NULL) { return; } cout << "***********************************************" << endl; cout <<"Name"<<"\t"<<p->ReaderName <<endl; cout <<"The ISBN number of the first book:"<<"\t"<<p->book1 <<endl; cout <<"The ISBN number of the second book:"<<"\t"<<p->book2 <<endl; } static void show_all() { Reader *q; q = head_point; while(q!=NULL) { cout<<q->ReaderName<<","<<q->Password<<","<<q->book1<<","<<q->book2<<endl; q = q->next ; } } static void change_password(Reader *p) //Modify password { if(p==NULL) { return; } Reader *point; point = head_point; while(strcmp(point->ReaderName ,p->ReaderName)!=0) { point=point->next;//Locate the logged-in user in the linked list } string n2; cout<<"Please enter a new password:"<<endl; cin>>n2; strcpy(point->Password,&n2[0]); load_readerfile(); cout<<"The change was successful!"<<endl; } static void delete_reader(Reader *p) //Reader logout { if(p==NULL) { return; } Reader *q;//Assist the point pointer, in p->next=point point = head_point; q = point; point = point->next; while((strcmp(point->ReaderName ,p->ReaderName)!=0)&&point!=NULL) { q=point; point=point->next; } q->next=point->next; delete point; load_readerfile(); cout<<"Log off successfully!"<<endl; o=o-1;//Reduce the number of readers by one } static void delete_readers() //Clear all reader information { cout<<"Are you sure you delete them all? Please delete them with caution. Please press 1 if you are sure, otherwise press the other keys."<<endl; char h; cin>>h; if(h=='1') { Reader *p,*q; p = head_point->next; while(p!=NULL) { q=p; p=p->next ; free(q); } head_point->next=NULL; load_readerfile(); cout<<"All readers' information has been successfully cleared!"<<endl; } else { return; } } static void help() { cout<<"No help for the time being, BALABALABALA"<<endl; } static void GoInto_ReaderInfo() //Reader Information Menu { char i; save_readerfile(); do { cout << "***********************************************" << endl; cout << "* Reader Function*" << endl; cout << "* *" << endl; cout << "* 1. Log in to view *" << endl; cout << "* *" << endl; cout << "* 2. Register *" << endl; cout << "* *" << endl; cout << "* 3. Log out *" << endl; cout << "* *" << endl; cout << "* 4. Modify password *" << endl; cout << "* *" << endl; cout << "* 5. View all readers' information# *" << endl; cout << "* *" << endl; cout << "* 6. Clear all reader information# *" << endl; cout << "* *" << endl; cout << "* 7. Help Notes *" << endl; cout << "* *" << endl; cout << "* 0. Return to the previous level *" << endl; cout << "* *" << endl; cout << "***********************************************" << endl; cout<<"# number is the administrator function, you need to log in to the administrator account <(ˉ^ˉ)> "<<endl; cout <<"Please enter the corresponding function code:"<<endl; cin >> i; Reader *p; switch (i) { case '1'://Login to view p = reader_land(); show_OneReader(p); break; case '2'://register p = reader_register(); Add_Point(p); cout<<"Registered successfully"<<endl; break; case '3'://Login cout<<"Login first to log in to the account you want to cancel to confirm that it is me"<<endl; p = reader_land(); delete_reader(p); break; case '4'://Modify password cout<<"Login first to change your password to confirm that it is me"<<endl; p = reader_land(); change_password(p); break; case '5': cout<<"Please log in to the administrator's account first and then perform the operation"<<endl; p = reader_land(); if((p==NULL)||strcmp(p->ReaderName,"guanliyuan")!=0)//Set the administrator as guanliyuan { cout<<"You are not an administrator and cannot do this"<<endl; break; } show_all(); break; case '6': cout<<"Please log in to the administrator's account first and then perform the operation"<<endl; p = reader_land(); if((p==NULL)||strcmp(p->ReaderName,"guanliyuan")!=0)//Set the administrator as guanliyuan { cout<<"You are not an administrator and cannot do this"<<endl; break; } delete_readers(); break; case '7': help(); break; case '0': break; default:cout << "Input error, please re-enter." << endl; } }while(i!='0'); } }; Reader* ReaderList::head_point=new Reader[sizeof(Reader)];//Reader head node Reader* ReaderList::point=new Reader[sizeof(Reader)];//Temporary Reader Node int ReaderList::o=1 ; class Book //Category that stores book information { public: char *BookName; // Book title, used to search char *Writer; //Author name, used to search char PublishDate[20]; // Publication date, used for search char ISBN[30]; //ISBN number, used to search char ebook[2]; //E-book char paperbook[2]; //Paper book char *Publisher; // Publisher, used to find char *BriefIntroduction; //Introduction to the book int i_o; //Judge whether the book is lent, 0 is on the shelf, 1 is lent Book *next; //Pointer to the next node }; /***Book Library List****/ class BookList { public: static Book * node; static Book *head_ptr ;//Define two Book pointers, head_ptr is the head pointer, and node\p is the active pointer static int n; BookList() { //Constructor, initialize pointer node = new Book[sizeof(Book)]; //Information for storing books head_ptr = new Book[sizeof(Book)]; head_ptr->next = NULL; node->next = NULL; } static void save_file() //Storage files { Book *p; //Temporary node fstream file; string s1,s2,s3,s4,s5,s6,s7,s8,s9; char a1[1000]; file.open("library//",ios::in | ios::out); if(!file) { cout<<"[save_file] not open file"<<endl; return; } getline(file,s1,','); head_ptr->BookName=new char[strlen(s1.c_str())+1]; strcpy(head_ptr->BookName,s1.c_str()); getline(file,s2,','); head_ptr->Writer=new char[strlen(s2.c_str())+1]; strcpy(head_ptr->Writer,s2.c_str()); getline(file,s3,','); strcpy(head_ptr->PublishDate,&s3[0]); getline(file,s4,','); strcpy(head_ptr->ISBN,&s4[0]); getline(file,s5,','); strcpy(head_ptr->ebook,&s5[0]); getline(file,s6,','); strcpy(head_ptr->paperbook,&s6[0]); getline(file,s7,','); head_ptr->Publisher=new char[strlen(s7.c_str())+1]; strcpy(head_ptr->Publisher,s7.c_str()); getline(file,s8); head_ptr->BriefIntroduction=new char[strlen(s8.c_str())+1]; strcpy(head_ptr->BriefIntroduction,s8.c_str()); node = head_ptr; while(!file.eof()) { p = new Book[sizeof(Book)]; getline(file,s1,','); if(s1=="")//Enhance the robustness. If the file is wrapped, the last behavior is empty. If it is not added, the last node will be incorrect. { break; } p->BookName=new char[strlen(s1.c_str())+1]; strcpy(p->BookName,s1.c_str()); getline(file,s2,','); p->Writer=new char[strlen(s2.c_str())+1]; strcpy(p->Writer,&s2[0]); getline(file,s3,','); strcpy(p->PublishDate,&s3[0]); getline(file,s4,','); strcpy(p->ISBN,&s4[0]); getline(file,s5,','); strcpy(p->ebook,&s5[0]); getline(file,s6,','); strcpy(p->paperbook,&s6[0]); getline(file,s7,','); p->Publisher=new char[strlen(s7.c_str())+1]; strcpy(p->Publisher,&s7[0]); getline(file,s8,'\n'); p->BriefIntroduction=new char[strlen(s8.c_str())+1]; strcpy(p->BriefIntroduction,&s8[0]); p->next=NULL; node -> next= p; node = p; // j++; n++;//The number of books // cout<<"Number of books: "<<n<<endl; } file.close(); delete p; } static void load_file() //Upload file { Book *q; q = head_ptr; fstream file; file.open("library//",ios::in | ios::out|ios::trunc); if(!file) { cout<<"[load_file] not open file"<<endl; } while(q!=NULL) { file<<q->BookName<<","<<q->Writer<<","<<q->PublishDate<<","<<q->ISBN<<","<<q->ebook<<","<<q->paperbook<<","<<q->Publisher<<","<<q->BriefIntroduction<<endl; q = q->next ; } file.close(); } static Book* AddNewBook() //Register new book, assign values ​​to class objects pointed to by node { string n1,n2,n3,n4,n5,n6,n7,n8; Book *nw; nw = new Book[sizeof(Book)]; cout<<"Please enter the following information for the new book:"<<endl; cout<<"Title of the Book:"<<endl; cin>>n1; cout<<"Author's name:"<<endl; cin>>n2; cout<<"Published Date:"<<endl; cin>>n3; cout<<"ISBN number:"<<endl; cin>>n4; cout<<"E-books (0 for shelf, 1 for loan):"<<endl; cin>>n5; cout<<"Paper book (0 is on shelf, 1 is loaned):"<<endl; cin>>n6; cout<<"Publisher:"<<endl; cin>>n7; cout<<"Content Introduction:"<<endl; cin>>n8; nw->BookName=new char[strlen(n1.c_str())+1]; nw->Writer=new char[strlen(n2.c_str())+1]; nw->Publisher=new char[strlen(n7.c_str())+1]; nw->BriefIntroduction=new char[strlen(n8.c_str())+1]; strcpy(nw->BookName,n1.c_str()); strcpy(nw->Writer,&n2[0]); strcpy(nw->PublishDate,&n3[0]); strcpy(nw->ISBN,&n4[0]); strcpy(nw->ebook,&n5[0]); strcpy(nw->paperbook,&n6[0]); strcpy(nw->Publisher,&n7[0]); strcpy(nw->BriefIntroduction,&n8[0]); nw->next = NULL; n=n+1; return nw; } static void Add_list(Book * p) //Add nodes to Book linked list, used when adding new books { node = head_ptr; while(node->next!=NULL)//Find the tail node { node=node->next; } node->next = p;//Connect a new node from the tail node = p; p->next=NULL;//Empty at the end load_file();//Update the file } static void borrow_book(Reader *p) //Borrowing procedures { Book *n; if (strcmp(p->book1," ")!=0 &&strcmp(p->book2 ," ")!=0) //Borrow books { cout<<"You have borrowed 2 books and can't borrow books anymore. You can return them first and then borrow them."<<endl; } else if(strcmp(p->book1," ")==0) { //Looking for a book n = search_ISBN(); //Borrow e-books at will, and only two paper books can be borrowed cout<<"Only record paper-based borrowing records, electronic paper-based books do not occupy the quota for borrowing books. Please download and view it yourself!"<<endl; if(strcmp(n->paperbook,"0")==0) { cout<<"《"<<n->BookName<<"》Paper books can be borrowed"<<endl; cout<<"Confirm Borrowing"<<n->BookName<<"》Are you a paper book? (Please press 1 if you confirm, otherwise press any other key)"<<endl; char temp; cin>>temp; if(temp=='1') { strcpy(p->book1,n->ISBN);//Record the ISBN number of the borrowed book strcpy(n->paperbook,"1");//Lend the book, 0->1, which means it is no longer available ReaderList::load_readerfile();//Update user information BookList::load_file();//Update library information cout<<"Borrowing the book successfully!!"<<endl; } } else { cout<<"none""<<n->BookName<<"》"<<endl; }//If you want to borrow 20 books, you can string books into a linked list, which is a bit troublesome } else if(strcmp(p->book2," ")==0) { //Looking for a book n = search_ISBN(); //Borrow e-books at will, and only two paper books can be borrowed cout<<"Only record paper-based borrowing records, electronic paper-based books do not occupy the quota for borrowing books. Please download and view it yourself!"<<endl; if(strcmp(n->paperbook,"0")==0) { cout<<"《"<<n->BookName<<"》Paper books can be borrowed"<<endl; cout<<"Confirm Borrowing"<<n->BookName<<"》Are you a paper book? (Please press 1 if you confirm, otherwise press any other key)"<<endl; char temp; cin>>temp; if(temp=='1') { strcpy(p->book2,n->ISBN);//Record the ISBN number of the borrowed book strcpy(n->paperbook,"1");//Lend the book, 0->1, which means it is no longer available ReaderList::load_readerfile();//Update user information BookList::load_file();//Update library information cout<<"Borrowing the book successfully!!"<<endl; } } else { cout<<"none""<<n->BookName<<"》"<<endl; } } else { cout<<"Borrowing a book failed"<<endl; } } static void return_book(Reader *p) //Return the book procedures { cout << "***********************************************" << endl; cout <<"Name"<<"\t"<<p->ReaderName <<endl; cout <<"book1"<<"\t"<<p->book1 <<endl; cout <<"book2"<<"\t"<<p->book2 <<endl; cout<<"Return to book1 (press 1), return to book2 (press 2),"<<endl; char hua; cin>>hua; Book *u; if(hua=='1'&&p->book1!=" ") { u=BookList::head_ptr; while(u!=NULL) { if(strcmp(u->ISBN,p->book1)==0) { strcpy(u->paperbook,"0");//On the rack is 0 strcpy(p->book1 ," ");//It will be empty after returning the book ReaderList::load_readerfile();//Update user information BookList::load_file();//Update library information cout<<"Successfully returned the book"<<endl; break; }u=u->next ; } if(u==NULL) { cout<<"No this book! The return failed, please check the ISBN number"<<endl; } } else if(hua=='2'&&p->book2!=" ") { u=BookList::head_ptr; while(u!=NULL) { if(strcmp(u->ISBN ,p->book2)==0) { strcpy(u->paperbook,"0");//On the rack is 0 strcpy(p->book2 ," ");//It will be empty after returning the book ReaderList::load_readerfile();//Update user information BookList::load_file();//Update library information cout<<"Successfully returned the book"<<endl; break; }u=u->next ; } if(u==NULL) { cout<<"No this book! The return failed, please check the ISBN number"<<endl; } } else { cout<<"Input error!"<<endl; } } static void show_book(Book *p) { cout << "***********************************************" << endl; cout<<"Book Name"<<"\t"<<p->BookName<<endl; cout<<"author"<<"\t"<<p->Writer<<endl; cout<<"Publishing Date"<<"\t"<<p ->PublishDate<<endl; cout<<"ISBN"<<"\t"<<p->ISBN<<endl; if(strcmp(p->ebook ,"0")==0) { cout<<"E-book"<<"\t"<<"In-Steps"<<endl; } if(strcmp(p->paperbook,"0")==0) { cout<<"Paper Book"<<"\t"<<"In-Steps"<<endl; } cout<<"Publisher"<<"\t"<<p->Publisher<<endl; cout<<"Book Introduction"<<"\t"<<p->BriefIntroduction<<endl; cout << "***********************************************" << endl; } static Book* search_ISBN() //Press ISBN number to find books { string cs; cout<<"Please enter the ISBN number of the book:"<<endl; cin>>cs; Book *p; p=head_ptr; while(p!=NULL) { if(strcmp(p->ISBN ,&cs[0])==0) { show_book(p); break; } p=p->next; } if(p==NULL) { cout<<"This book was not found, try looking for other books"<<endl; } return p; } static void search_BookName() //Find books by title { string cs; cout<<"Please enter the title of the book:"<<endl; cin>>cs; Book *p; int i=0; p=head_ptr; while(p!=NULL) { if(strcmp(p->BookName,&cs[0])==0) { show_book(p); i++; } p=p->next; } cout<<"Finished"<<i<<"The real name is "<<cs<<"""<<endl; } static void search_Writer() //Find books by author name { string cs; cout<<"Please enter the author name of the book:"<<endl; cin>>cs; Book *p; int i=0; p=head_ptr; while(p!=NULL) { if(strcmp(p->Writer,&cs[0])==0) { show_book(p); i++; } p=p->next; } cout<<"Finished"<<i<<"Book"<<cs<<"The Book"<<endl; } static void search_Publisher() //Click books by publisher { string cs; cout<<"Please enter the publisher of the book:"<<endl; cin>>cs; Book *p; int i=0; p=head_ptr; while(p!=NULL) { if(strcmp(p->Publisher,&cs[0])==0) { show_book(p); i++; } p=p->next; } cout<<"Finished"<<i<<"Book"<<cs<<"The Book"<<endl; } static void search_PublishDate() //Find books by publication date { string cs; cout<<"Please enter the publication date of the book:"<<endl; cin>>cs; int i=0; Book *p; p=head_ptr; while(p!=NULL) { if(strcmp(p->PublishDate,&cs[0])==0) { show_book(p); i++; } p=p->next; } cout<<"Finished"<<i<<"Book"<<cs<<"The Book"<<endl; } static void search() //Enter the search menu { char r; do { cout << "***********************************************" << endl; cout << "* Book Search *" << endl; cout << "* *" << endl; cout << "* 1. Press ISBN number to find books *" << endl; cout << "* *" << endl; cout << "* 2. Find books by title *" << endl; cout << "* *" << endl; cout << "* 3. Find books by author's name *" << endl; cout << "* *" << endl; cout << "* 4. Search for books by publisher *" << endl; cout << "* *" << endl; cout << "* 5. Find books by publication date *" << endl; cout << "* *" << endl; cout << "* 0. Return to the previous level *" << endl; cout << "* *" << endl; cout << "***********************************************" << endl; cout <<"Please enter the corresponding function code:"<<endl; cin>>r; switch(r) { case '1': search_ISBN(); break; case '2': search_BookName(); break; case '3': search_Writer(); break; case '4': search_Publisher(); break; case '5': search_PublishDate(); break; case '0': break; default:cout << "Input error, please enter again." << endl; } } while(r!='0'); } static void show_all() //Show all unlent books in stock { int i=0; Book *p; p=head_ptr->next; while(p!=NULL) { if(strcmp(p->ebook,"0")==0||strcmp(p->paperbook,"0")==0) { show_book(p); i++; } p=p->next; } cout<<"Finished"<<i<<"Books on shelf"<<endl; } static void delete_onebook() //Delete a book { string ss; cout<<"Please enter the ISBN number of the book you want to delete:"<<endl; cin>>ss; Book *p,*q; p = head_ptr; q=p; p = p->next ; while(strcmp(p->ISBN ,&ss[0])!=0) { q=p; p=p->next; } if(p==NULL) { cout<<"No record of the books you want to delete"<<endl; } else { q->next=p->next; p->next=NULL; delete p; load_file(); cout<<"Delete successfully!"<<endl; n=n-1; } } static void delete_allbook() //Delete all books { cout<<"Are you sure you delete them all?, please delete them with caution. Please press 1 if you are sure, otherwise press other keys."<<endl; char h; cin>>h; if(h!='1') { return; } else { Book *p,*q; p = head_ptr->next; while(p!=NULL) { q=p; p=p->next ; free(q); } head_ptr->next=NULL; load_file(); cout<<"All books were deleted successfully!"<<endl; } } static void change_content() //Change the information of a book { Book *p; p = search_ISBN(); if(p==NULL) { return; } string n1,n2,n3,n4,n5,n6,n7; char i=' '; do { cout << "***********************************************" << endl; cout << "* Modify Book Information*" << endl; cout << "* *" << endl; cout << "* 1. Modify the title *" << endl; cout << "* *" << endl; cout << "* 2. Modify the author's name *" << endl; cout << "* *" << endl; cout << "* 3. Modify the publication date *" << endl; cout << "* *" << endl; cout << "* 4. Modify the e-book (0 is on the shelf, 1 is loaned) *" << endl; cout << "* *" << endl; cout << "* 5. Modify the paper book (0 is on the shelf, 1 is loaned) *" << endl; cout << "* *" << endl; cout << "* 6. Modify the publisher *" << endl; cout << "* *" << endl; cout << "* 7. Introduction to the modification content *" << endl; cout << "* *" << endl; cout << "* 0. Return to the previous level *" << endl; cout << "* *" << endl; cout << "***********************************************" << endl; cout<<endl<<endl; cout <<"Please enter the corresponding function code:"<<endl; cin >> i; switch (i) { case '1': cout<<"New Title:"<<endl; cin>>n1; strcpy(p->BookName,&n1[0]);//Modify directly in the linked list break; case '2': cout<<"New Author Name:"<<endl; cin>>n2; strcpy(p->Writer,&n2[0]); break; case '3': cout<<"New publication date:"<<endl; cin>>n3; strcpy(p->PublishDate,&n4[0]); break; case '4': cout<<"E-books (0 for shelf, 1 for loan):"<<endl; cin>>n4; strcpy(p->ebook,&n4[0]); break; case '5': cout<<"Modify the paper book (0 is on shelf, 1 is loaned):"<<endl; cin>>n5; strcpy(p->paperbook,&n5[0]); break; case '6': cout<<"New Publisher:"<<endl; cin>>n6; strcpy(p->Publisher,&n6[0]); break; case '7': cout<<"New content introduction:"<<endl; cin>>n7; strcpy(p->BriefIntroduction,&n7[0]); break; case '0': break; default:cout << "Input error, please enter again." << endl; } }while(i!='0'); cout<<"Revised Book"<<endl; show_book(p); load_file(); } static void GoInto_BookInfo(ReaderList rel) //Enter the library information menu { Book *p; Reader *r; save_file(); rel.save_readerfile();//Download reader information char i=' '; do { cout << "***********************************************" << endl; cout << "* Book Information Management*" << endl; cout << "* *" << endl; cout << "* 1. New books are included in the library# *" << endl; cout << "* *" << endl; cout << "* 2. Find *" << endl; cout << "* *" << endl; cout << "* 3.Delete# *" << endl; cout << "* *" << endl; cout << "* 4. Modify# *" << endl; cout << "* *" << endl; cout << "* 5. Show all books on shelf *" << endl; cout << "* *" << endl; cout << "* 6. Clear all book content# *" << endl; cout << "* *" << endl; cout << "* 0. Return to the previous level *" << endl; cout << "* *" << endl; cout << "***********************************************" << endl; cout<<"# number is the administrator function, you need to log in to the administrator account <(ˉ^ˉ)> "<<endl; cout <<"Please enter the corresponding function code:"<<endl; cin >> i; switch (i) { case '1': cout<<"Please log in to the administrator's account first and then perform the operation"<<endl; r = rel.reader_land();//Admin Login if((r==NULL)||strcmp(r->ReaderName,"guanliyuan")!=0)//Set the administrator as guanliyuan { cout<<"You are not an administrator and cannot do this"<<endl; break; } p = AddNewBook(); Add_list(p); cout<<"New book insertion successfully"<<endl; break; case '2': search(); break; case '3': cout<<"Please log in to the administrator's account first and then perform the operation"<<endl; r = rel.reader_land();//Admin Login if((r==NULL)||strcmp(r->ReaderName,"guanliyuan")!=0)//Set the administrator as guanliyuan { cout<<"You are not an administrator and cannot do this"<<endl; break; } delete_onebook(); break; case '4': cout<<"Please log in to the administrator's account first and then perform the operation"<<endl; r = rel.reader_land();//Admin Login if((r==NULL)||strcmp(r->ReaderName,"guanliyuan")!=0)//Set the administrator as guanliyuan { cout<<"You are not an administrator and cannot do this"<<endl; break; } change_content(); break; case '5': show_all(); break; case '6': cout<<"Please log in to the administrator's account first and then perform the operation"<<endl; r = rel.reader_land();//Admin Login if((r==NULL)||strcmp(r->ReaderName,"guanliyuan")!=0)//Set the administrator as guanliyuan { cout<<"You are not an administrator and cannot do this"<<endl; break; } delete_allbook(); break; case '0': break; default:cout << "Input error, please enter again." << endl; } }while(i!='0'); } }; int BookList::n ; Book* BookList::head_ptr=new Book[sizeof(Book)]; Book* BookList::node=new Book[sizeof(Book)]; void borrowtoreturn(BookList b,ReaderList r) //Borrowing books and returning books. Determine whether it is "borrowing books" or "returning books". 1 is "borrowing books", 2 is "returning books" { int k= 0; int rsuffix, bsuffix; string readername,readerpass;//Store the reader's name and password cout<<"Please enter your name:"<<endl;; cin >> readername; Reader *p; p=r.head_point; while(p!=NULL) { if(strcmp(p->ReaderName,&readername[0])==0) { cout<<"Please enter your password:"; cin>> readerpass; if(strcmp(p->Password,&readerpass[0])==0) { cout<<"Login successfully!"<<endl; k=1;break; } else { cout<<"Error password!"<<endl; k=0;return; } } p=p->next; } if(k=0) { cout<<"Input Error"<<endl; return; } char br=' '; do { cout << "***********************************************" << endl; cout << "* Borrowing / Returning Book*" << endl; cout << "* *" << endl; cout << "* 1. Borrowing Book*" << endl; cout << "* *" << endl; cout << "* 2. Return to the book *" << endl; cout << "* *" << endl; cout << "* 0. Exit *" << endl; cout << "* *" << endl; cout << "***********************************************" << endl; cout<<endl<<endl; cout <<"Please enter the corresponding function code:"<<endl; cin>>br; switch (br) { case '1': b.borrow_book(p); break; case '2': b.return_book(p); break; case '0': break; default: cout<<"Input error!"<<endl; break; } } while (br!='0'); } void mainjiemian() //Main interface //Main interface { cout << "***********************************************" << endl; cout << "* Book Borrowing System*" << endl; cout << "* *" << endl; cout << "* 1. Reader Information *" << endl; cout << "* *" << endl; cout << "* 2. Library Information *" << endl; cout << "* *" << endl; cout << "* 3.Borrow books/return books *" << endl; cout << "* *" << endl; cout << "* 4. Help *" << endl; cout << "* *" << endl; cout << "* 5. Some instructions on the system *" << endl; cout << "* *" << endl; cout << "* 0. Exit the system *" << endl; cout << "* *" << endl; cout << "***********************************************" << endl; cout <<"Please enter the corresponding function code"<<endl; } void help() { cout<<"You can register, log in, borrow books, and return books"<<endl; } void notes() { cout<<"===============================================================================================<<endl; cout<<"THIS FILE IS PART OF Library lending system PROJECT"<<endl; cout<<"THIS FILE CAN ONLY BE USED FOR LEARNING , NOT FOR COMMERCIAL PROFIT."<<endl; cout<<"Copyright (c) 2020-2022 Zijin JDD "<<endl; } int main() { BookList b; ReaderList r; char in=' '; do { mainjiemian(); cin >> in; switch (in) { case '1': r.GoInto_ReaderInfo(); break; case '2': b.GoInto_BookInfo(r); break; case '3': b.save_file();//Download library information to link table r.save_readerfile();//Download reader information to link table borrowtoreturn(b,r); break; case '4': help(); break; case '5': notes(); break; case '0': return 0; default:cout << "Input error, please re-enter." << endl; } } while (in != '0'); system("pause"); return 0; }