Library Management System

Keywords: Programming iOS

Problem description

The system requires the establishment of a library management system, which has the functions of storage, update, query, statistics, ranking, output, and book borrowing and booking. Through this subject, we can master the data type, programming statement, function definition and invocation method and modularization idea of advanced programming language.

Functional requirements

(1) Each kind of book contains information such as book serial number, book name, book type, total stock of books, current stock of books, author, stock location, loan status, etc.

(2) Functions to be implemented

1. The system can be used to store, update, inquire, count, arrange and output the basic information of books in order to realize the management of books.

2. The updating functions include: adding information, deleting information, modifying information, adding one or more book information according to need, or deleting or modifying individual book information appropriately, so as to update book information at any time.

3. The query function designed in the program can query a certain book information from a number of data according to need, and can be queried by four different methods: name query, category query, author query, book name and author query to meet different needs.

4. Real-time update of the status of book borrowing and returning and the status of book inventory.

(3) Friendly interface.

Note: In order to make the system more humane and contemporary, after consulting teachers, we add the following functions to enrich the system.

1. Increase the reader's rights and distinguish them from administrators'rights. Administrators need passwords to log in and readers need reader numbers to log in.

2. Readers can register their own accounts, one account and borrow up to 10 books at the same time.

3. Readers can return books by themselves, check their borrowing information, and Book reservations.

4. Readers can inquire about books in the library, bookings, etc.

5. Push the highest book borrowing and the ranking of the readers to the readers, and the readers can check it in their own information.

6. Readers can also borrow books at the loan counter through the administrator.

7. Administrators can check the arrival of bookings in order to notify the bookers.

8. Administrators can check the total number of books borrowed and returned

9. We can sort and observe the amount of books borrowed or the search number.

Note: Readers can write their own test files in txt format, or the machine can modify the code to other formats.

Code

#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <string>  
#include <vector>  
#include <algorithm>  
#include <fstream>  
#include <cctype>  
#include <iomanip>  
#include <conio.h>  
using namespace std;  
struct student  
{  
    int id;//Reader number  
    string name;//Name of reader  
    int borrowsum;//How many books have you borrowed by default of 0  
    int number;//How many books are still outstanding by default of 0  
    string borrowday;//Last borrowing time, default is 0000.00.00  
    int b[10];//The number of the book you borrowed, up to 10  
};  
struct book  
{  
    int idnum;//Book Retrieval Number  
    int BorrowCount;//Book borrowing volume, initialized to 0  
    string name;//Title  
    string kind;//Book type  
    double price;//Book price  
    int sum;//Total stock of books  
    int nowsum;//Current stock of books  
    string author;//Book author  
    int appointment;//Book reservation, initialized to 0  
    bool ok;//Is it possible to borrow? Initially, it is possible to borrow.  
    string borrowdate;//The latest book lending time, default is 0000-00-00;  
    string returndate;//The latest return time of the book is 0000-00-00 by default.  
    string room;//Holdings  
};  
bool cmpByidnum(book a,book b)  
{  
    return a.idnum<b.idnum;  
}  
bool cmpByCount(book a,book b)  
{  
    return a.BorrowCount>b.BorrowCount;  
}  
bool cmpByBorrowsum(student a,student b)  
{  
    return a.borrowsum>b.borrowsum;  
}  
bool cmpByid(student a,student b)  
{  
    return a.id<b.id;  
}  
class Library  
{  
private:  
    int borrownum;//Number of books lent each month  
    int returnnum;//Number of book returns per month  
    vector<book> data;  
    vector<student> data1;  
    vector<int> betoli;//Appointment to the library, store its number  
public:  
    Library();  
    void AddBook(book NewBook);  //Increase books  
    void DeleteBook(string bookname,string author);//Delete books  
    void BorrowBook(string name,string author);//Borrowing books  
    void BackBook(string name,string author,int k);//Return books  
    void ShowAllBook(); //Output System All Books  
    void  SearchBookPosWithname(string thebook); //Search by title  
    void  SearchBookPosWithAuthor(string theauthor);//Query by author  
    void  SearchBookPosWithKind(string kind);//Query by category  
    int  SearchBookPosWithAB(string theauthor,string thebook);//Search by author and title  
    int  SearchBookPosWithid(int id); //Search by search number  
    void SortBook(int ca);  //sort  
    void SortStudent(int ca);//Sort by reader's borrowing volume  
    void Save();  //Store in Library Documents  
    void Save1();//Deposit Student Documents  
    void Appointment(string bookname,string author);//Book reservation  
    void printbook(book a);//Output all information about a Book  
    void revisebook(string name,string author);//Modify the information of a Book  
    int SerchStudent(int id);//Query a reader  
    //Int Serch Student 1 (int id);//Query a reader  
    void AddStudent(student a);//Add a reader  
    void PrintStudent(int kid);//Output Reader Information  
    int GetStudent();//Return the total number of readers  
    int readsum(int id);//Get a reader's borrowing  
    int getborrownum();//Get the loan for this month  
    int getreturnnum();//Get the amount of books returned this month  
    void PrintToLi();//Export to Library Reservations  
};  
Library::Library()  
{  
    borrownum=0;  
    returnnum=0;  
    int AllBook,AllStudent;  
    ifstream fin("book.txt");  
    if(fin)  
    {  
        fin>>AllBook;  
        for(int i=0; i<AllBook; i++)  
        {  
            book tem;  
            fin>>tem.idnum>>tem.name>>tem.author>>tem.price>>tem.kind>>tem.room>>tem.sum>>tem.nowsum>>tem.BorrowCount>>tem.ok>>tem.appointment>>tem.borrowdate>>tem.returndate;  
            data.push_back(tem);  
        }  
        fin.close();  
    }  
    //cin.clear();  
    //cin.sync();  
    ifstream tfin("student.txt");  
    if(tfin)  
    {  
        tfin>>AllStudent;  
        for(int i=0; i<AllStudent; i++)  
        {  
            student tem;  
            tfin>>tem.id>>tem.name>>tem.borrowsum>>tem.number>>tem.borrowday;  
            for(int j=0;j<10;j++)  
            {  
                tfin>>tem.b[j];  
            }  
            data1.push_back(tem);  
        }  
        tfin.close();  
    }  
}  
int Library::readsum(int a)  
{  
    //SortStudent(1);  
    return data1[a-1].borrowsum;  
}  
int Library::getborrownum()//Get the loan for this month  
{  
    return borrownum;  
}  
int Library::getreturnnum()//Get the amount of books returned this month  
{  
    return returnnum;  
}  
int Library::GetStudent()  
{  
    int k=(int)data1.size();  
    return k+1;  
}  
void Library::AddBook(book NewBook)  
{  
    data.push_back(NewBook);  
}  
void Library::AddStudent(student newstudent)  
{  
    data1.push_back(newstudent);  
}  
void Library::DeleteBook(string bookname,string author)  
{  
    int pos = SearchBookPosWithAB(author,bookname);  
    if (pos!=-1)  
    {  
        data.erase(data.begin()+pos);  
        return ;  
    }  
    else  
        cout<<"No book!\n";  
}  
void Library::BorrowBook(string name,string author)  
{  
    string BorrowDate;  
    string BackDate;  
    char c;  
    int flag=0;  
    SortStudent(1);  
    int sid=-1;  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].name==name&&data[i].author==author)  
        {  
            if(data[i].nowsum)  
            {  
                cout<<"The reader number of the borrower is:";  
                cin>>sid;  
                if(data1[sid-1].number>10)  
                {  
                    cout<<"Now you have borrowed 10 books at the same time! No more borrowing!"<<endl;  
                    break;  
                }  
                flag=1;  
                data[i].nowsum=data[i].nowsum-1;  
                data[i].BorrowCount=data[i].BorrowCount+1;  
                cout<<"Please enter the borrowing date."<<endl;  
                cin>>BorrowDate;  
                data[i].borrowdate=BorrowDate;  
                cout<<"Please enter the expected return date.(It can be borrowed for up to one month.)"<<endl;  
                cin>>BackDate;  
                data[i].returndate=BackDate;  
                data[i].ok=bool(data[i].nowsum);  
                borrownum++;  
                data1[sid-1].number++;  
                for(int j=0;j<10;j++)  
                {  
                    if(data1[sid-1].b[j]==0)  
                    data1[sid-1].b[j]=data[i].idnum;  
                    Save();  
                    Save1();  
                }  
            }  
            else  
            {  
                cout<<"~~~~(>_<)~~~~ !This book has been borrowed! Do you have an appointment? Y/N"<<endl;  
                cin>>c;  
                c=toupper(c);  
                if(c=='Y')  
                    data[i].appointment++;  
            }  
        }  
    }  
    if(!flag)  
        cout<<"Sorry, I can't find the book you are looking for."<<endl;  
}  
void Library::BackBook(string name,string author,int k)//k means the way to return the book  
{  
    int c=-1;  
    SortStudent(1);  
    if(k!=-1)//Readers'Self-help Return Books  
    {  
        c=k-1;  
    }  
    else//Readers return books by borrowing and returning them to the front desk  
    {  
        cout<<"Please enter your reader number:";  
        cin>>c;  
        c=c-1;  
    }  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].name==name&&data[i].author==author)  
        {  
            data[i].nowsum=data[i].nowsum+1;  
            data[i].ok=bool(data[i].nowsum);  
            returnnum++;  
            if(data[i].appointment!=0)  
            {  
                data[i].appointment--;  
                betoli.push_back(data[i].idnum);  
            }  
            for(int j=0;j<10;j++)  
                {  
                    if(data1[c].b[j]==data[i].idnum)  
                        data1[c].b[j]=0;  
                }  
                data1[c].number--;  
            break;  
        }  
    }  
    Save();  
    Save1();  
}  
void Library::printbook(book a)  
{  
    cout<<setw(8)<<a.idnum;  
    cout<<setw(14)<<a.name;  
    cout<<setw(14)<<a.author;  
    cout<<setw(14)<<fixed<<setprecision(2)<<a.price;  
    cout<<setw(14)<<a.kind;  
    cout<<setw(14)<<a.room;  
    cout<<setw(14)<<a.sum;  
    cout<<setw(14)<<a.nowsum;  
    cout<<setw(14)<<a.BorrowCount;  
    cout<<setw(10)<<(a.ok==0?"Not to lend":"May borrow");  
    cout<<setw(14)<<a.appointment;  
    cout<<setw(14)<<a.borrowdate;  
    cout<<setw(14)<<a.returndate<<endl;  
    // cout<<endl;  
}  
void Library::PrintToLi()  
{  
    SortBook(1);  
    int k=(int)betoli.size();  
    if(!k) cout<<"     No booking for the moment!"<<endl;  
    else  
    {  
        cout<<"        Reservations to the library are as follows:\n";  
        for(int i=0;i<k;i++)  
        {  
            printbook(data[betoli[i]-1]);  
        }  
    }  
}  
void Library::PrintStudent(int kid)  
{  
   int id=kid-1;  
    //id=SerchStudent(id);  
    SortStudent(1);  
    SortBook(1);  
    //SortStudent(1);  
    cout<<setw(8)<<data1[id].id;  
    cout<<setw(8)<<data1[id].name;  
    cout<<setw(14)<<data1[id].borrowsum;  
    cout<<setw(18)<<data1[id].number;  
    cout<<setw(14)<<data1[id].borrowday<<endl;  
    if(data1[id].number)  
    {  
        cout<<"You are currently borrowing these books:\n";  
        cout<<setw(16)<<"Search number"<<setw(16)<<"Title"<<setw(16)<<"author"<<endl;  
        for(int i=0;i<10;i++)  
        {  
            if(data1[id].b[i]!=0)  
            cout<<setw(16)<<data[data1[id].b[i]-1].idnum<<setw(16)<<data[data1[id].b[i]-1].name<<setw(16)<<data[data1[id].b[i]-1].author<<endl;  
        }  
    }  
    else  
        cout<<"You haven't borrowed any books at the moment.,Go and borrow a book.\n";  
}  
void Library::ShowAllBook()  
{  
    //system("cls");  
    cout<<setw(8)<<"Search number"<<setw(14)<<"Title"<<setw(14)<<"author"<<setw(14)<<"Price"<<setw(14)<<"type"<<setw(14)<<"Holdings"<<setw(14)<<"Total inventory"<<setw(14)<<"In Library volume"<<setw(14)<<"Borrowing volume"<<setw(10)<<"Can I borrow it?"<<setw(14)<<"Allocated Quantity";  
    cout<<setw(14)<<"Lending time"<<setw(14)<<"Return time"<<endl;  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        //cout<<endl;  
        printbook(data[i]);  
        //cout<<endl;  
        /*cout<<setw(6)<<data[i].idnum; 
        cout<<setw(16)<<data[i].name; 
        cout<<setw(8)<<data[i].author; 
        cout<<setw(6)<<fixed<<setprecision(2)<<data[i].price; 
        cout<<setw(6)<<data[i].kind; 
        cout<<setw(16)<<date[i].room; 
        cout<<setw(6)<<data[i].sum; 
        cout<<setw(6)<<data[i].nowsum; 
        cout<<setw(6)<<data[i].BorrowCount; 
        cout<<setw(6)<<(data[i].borrow==0?"Can not borrow ":" can borrow "; 
        cout<<setw(6)<<date[i].appointment; 
        cout<<setw(14)<<date[i].borrowdate; 
        cout<<setw(14)<<date[i].returndate<<endl;*/  
    }  
}  
int Library::SerchStudent(int id)  
{  
    int m=-1;  
     for (int i = 0; i <(int)data1.size(); i++)  
     {  
        if (data1[i].id==id)  
        {  
            return i;  
        }  
     }  
     return m;  
 }  
void Library::SearchBookPosWithname(string thebook)//Search by title  
{  
    int flag=0;  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].name==thebook)  
        {  
            printbook(data[i]);  
            flag=1;  
        }  
    }  
    if(!flag) cout<<"No book!\n";  
}  
void Library::SearchBookPosWithAuthor(string theauthor)//Query by author  
{  
    bool flag=false;  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].author==theauthor)  
        {  
            flag=true;  
            printbook(data[i]);  
        }  
    }  
    if(!flag) cout<<"No book by this author!";  
}  
void Library::SearchBookPosWithKind(string kind)//Query by category  
{  
    bool flag=false;  
    for (int i = 0; i <(int)data.size(); ++i)  
    {  
        if (data[i].kind==kind)  
        {  
            flag=true;  
            printbook(data[i]);  
        }  
    }  
    if(!flag) cout<<"No such books!";  
}  
int Library::SearchBookPosWithAB(string theauthor,string thebook)//Search by author and title  
{  
    for (int i = 0; i <(int)data.size(); ++i)  
    {  
        if (data[i].author==theauthor&&data[i].name==thebook)  
        {  
            printbook(data[i]);  
            return i;  
        }  
    }  
    cout<<"No book!";  
    return -1;  
}  
int Library::SearchBookPosWithid(int id)  
{  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].idnum==id)  
        {  
            return i;  
        }  
    }  
    return -1;  
}  
void Library::SortBook(int ca)  //sort  
{  
    if (ca==0)   //Sort by borrowing amount  
    {  
        sort(data.begin(),data.end(),cmpByCount);  
    }  
    else    //Sort by search number  
    {  
        sort(data.begin(),data.end(),cmpByidnum);  
    }  
}  
void Library::SortStudent(int ca)  
{  
    if(ca==0)//Sort by borrowing amount  
        sort(data1.begin(),data1.end(),cmpByBorrowsum);  
    else  
        sort(data1.begin(),data1.end(),cmpByid);//Sort by reader number  
}  
void Library::Save() //Store in books and documents  
{  
    ofstream fout("book.txt");  
    if (fout)  
    {  
        fout<<data.size()<<endl;  
        //book p;  
        for (int i = 0; i <(int)data.size(); i++)  
        {  
            fout<<data[i].idnum<<" "<<data[i].name<<" "<<data[i].author<<" "<<data[i].price<<" "<<data[i].kind<<" "<<data[i].room<<" "<<data[i].sum<<" "<<data[i].nowsum<<" "<<data[i].BorrowCount<<" "<<data[i].ok<<" "<<data[i].appointment<<" "<<data[i].borrowdate<<" "<<data[i].returndate<<" "<<endl;  
        }  
        fout.close();  
    }  
}  
void Library::Save1() //Deposit Student Documents  
{  
    ofstream fout("student.txt");  
    if (fout)  
    {  
        fout<<data1.size()<<endl;  
        //student p;  
        for (int i = 0; i <(int)data1.size(); i++)  
        {  
            fout<<data1[i].id<<" "<<data1[i].name<<" "<<data1[i].borrowsum<<" "<<data1[i].number<<" "<<data1[i].borrowday;  
            for(int j=0;j<10;j++)  
            {  
                fout<<" "<<data1[i].b[j];  
            }  
            fout<<endl;  
        }  
        fout.close();  
    }  
}  
void Library::revisebook(string name,string author)//Revision of books  
{  
    string Room,Kind;  
    int num,k=0;  
    printf("The content you want to modify is:\n");  
    printf("                 1.Collection modification\n");  
    printf("                 2.Modification of the Total Stock of Books\n");  
    printf("                 3.Modification of the Category of Books\n");  
    printf("                 4.Sign out\n");  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].author==author&&data[i].name==name)  
        {  
            k=i;  
            break;  
        }  
    }  
    int cho;  
    do  
    {  
        cin>>cho;  
        switch(cho)  
        {  
        case 1:  
        {  
            cout<<"Please enter a new collection:\n";  
            cin>>Room;  
            data[k].room=Room;  
            break;  
        }  
        case 2:  
        {  
            cout<<"Please enter a new total inventory:\n";  
            cin>>num;  
            data[k].sum=num;  
            break;  
        }  
        case 3:  
        {  
            cout<<"Please enter a new category of books:\n";  
            cin>>Kind;  
            data[k].kind=Kind;  
            break;  
        }  
        }  
    }  
    while(cho<4);  
}  
void Library::Appointment(string bookname,string author)//Book reservation  
{  
    for (int i = 0; i <(int)data.size(); i++)  
    {  
        if (data[i].author==author&&data[i].name==bookname)  
        {  
            if(data[i].nowsum>0) printf("There are books in the library. You don't have to make an appointment!\n");  
            else  
            {  
                data[i].appointment++;  
                printf("The appointment was successful!");  
            }  
        }  
    }  
}  
int main()  
{  
    cout.setf(ios::left);//Left alignment  
    Library mybook;  
    char mm[6];//Cipher array  
   // mybook.PrintStudent(0);  
    cout<<"                                                   Welcome to use the library management system"<<endl;  
    cout<<"Please select your login options:\n";  
    cout<<"                  1.Administrator login"<<endl;  
    cout<<"                  2.Reader login"<<endl;  
    int cho,start,kk=1;  
    cin>>start;  
    switch(start)  
    {  
        case 1:  
       {  
        char password[]="192021";  
       // string passwdInput;  
        cout<<"Please enter the administrator password:";  
        do{  
            kk=1;  
           for(int i=0;i<6;i++)  
           {  
            mm[i]=getch();  
            cout<<"*";  
           }  
           cout<<endl;  
           for(int i=0;i<6;i++)  
           {  
           if (mm[i]!=password[i])  
           {  
            cout<<"Please enter the correct password!"<<endl;  
            kk=0;  
            break;  
           }  
           }  
        }while(!kk);  
        do  
        {  
           // Cout < < welcome to use the library management system > endl;  
            cin.clear();  
            cin.sync();  
            //system("cls");  
            cout<<"              1.All book catalogues "<<endl;  
            cout<<"              2.Query books "<<endl;  
            cout<<"              3.Increase books "<<endl;  
            cout<<"              4.Delete books "<<endl;  
            cout<<"              5.Borrowing books "<<endl;  
            cout<<"              6.Return books "<<endl;  
            cout<<"              7.Modifying Book Information "<<endl;  
            cout<<"              8.Lending statistics for this month "<<endl;  
            cout<<"              9.Arrival of Reservations "<<endl;  
            cout<<"              10.Sign out "<<endl;  
            cout<<"-------------------------------------------------------------------------------------------------------------------"<<endl;  
            cout<<"              Please select the function,Input instruction "<<endl;  
            cin>>cho;  
            switch(cho)  
            {  
            case 1:  
            {  
                int cho2;  
                do  
                {  
                    mybook.ShowAllBook();  
                    cout<<"-------------------------------------------------------------------------------------------------------------------------------------------------------------"<<endl;  
                    cout<<"0:Sort by borrowing amount , 1:Sort by index number ,3:Sign out"<<endl;  
                    cin>>cho2;  
                    switch(cho2)  
                    {  
                    case 0:  
                        mybook.SortBook(0);  
                        break;  
                    case 1:  
                        mybook.SortBook(1);  
                        break;  
                    }  
                }  
                while (cho2<2);  
                break;  
            }  
            case 2:  
            {  
                cout<<"              1.Search by title "<<endl;  
                cout<<"              2.Query by author "<<endl;  
                cout<<"              3.Query by category "<<endl;  
                cout<<"              4.Search by title and author "<<endl;  
                cout<<"              5.Sign out "<<endl;  
                cout<<"              Please select the function,Input instruction "<<endl;  
                int cho3;  
                do  
                {  
                    string Name,AutHor,Kind;  
                    cin>>cho3;  
                    switch(cho3)  
                    {  
                    case 1:  
                        cout<<"Please enter the title of the book!"<<endl;  
                        cin>>Name;  
                        mybook.SearchBookPosWithname(Name); //Search by title  
                        break;  
                    case 2:  
                        cout<<"Please enter the author!"<<endl;  
                        cin>>AutHor;  
                        mybook.SearchBookPosWithAuthor(AutHor);//Query by author  
                        break;  
                    case 3:  
                        cout<<"Please enter the category!"<<endl;  
                        cin>>Kind;  
                        mybook.SearchBookPosWithKind(Kind);//Query by category  
                        break;  
                    case 4:  
                        cout<<"Please enter the author and title!"<<endl;  
                        cin>>AutHor>>Name;  
                        mybook.SearchBookPosWithAB(AutHor,Name);//Search by author and title  
                        break;  
                    }  
                }  
                while(cho3<=4&&cho3>=1);  
                break;  
            }  
            case 3:         //Increase books  
            {  
                book temp;  
                cout<<"Please enter the search number.:";  
                cin>>temp.idnum;  
                while (mybook.SearchBookPosWithid(temp.idnum)>-1)  
                {  
                    cout<<"The search number is repeated!~~~~(>_<)~~~~ !"<<endl;  
                    cin>>temp.idnum;  
                }  
                cin.clear();  
                cin.sync();  
                cout<<"Title:";  
                cin>>temp.name;  
                cout<<"Author:";  
                cin>>temp.author;  
                cout<<"Price:";  
                cin>>temp.price;  
                cout<<"type:";  
                cin>>temp.kind;  
                cout<<"Address of Library:";  
                cin>>temp.room;  
                cout<<"Number:";  
                cin>>temp.sum;  
                temp.nowsum=temp.sum;  
                temp.BorrowCount=0;  
                temp.ok=true;  
                temp.appointment=0;  
                temp.borrowdate="0000.00.00";  
                temp.returndate="0000.00.00";  
                mybook.AddBook(temp);  
                mybook.Save();  
                cout<<"Successful Information Preservation"<<endl;  
                break;  
            }  
            case 4:         //Delete books  
            {  
                string bookname,bookauthor;  
                cout<<"Please enter the title and author of the book.:"<<endl;  
                cin>>bookname>>bookauthor;  
                mybook.DeleteBook(bookname,bookauthor);  
                break;  
            }  
            case 5:         //Borrow books  
            {  
                string bookname,bookauthor;  
                cout<<"Please enter the title and author of the book you want to borrow:"<<endl;  
                cin>>bookname>>bookauthor;  
                mybook.BorrowBook(bookname,bookauthor);  
                mybook.Save();  
                break;  
            }  
            case 6:         //Return books  
            {  
                string bookname,bookauthor;  
                cout<<"Please enter the title and author of the book to be returned:"<<endl;  
                cin>>bookname>>bookauthor;  
                mybook.BackBook(bookname,bookauthor,-1);  
                mybook.Save();  
                break;  
            }  
            case 7:  
            {  
                string name,author;  
                cout<<"Please enter the title and author of the book to be modified:"<<endl;  
                cin>>name>>author;  
                mybook.revisebook(name,author);  
                break;  
            }  
            case 8:  
            {  
                  printf("                     Borrowing books this month%d second\n",mybook.getborrownum());  
                  printf("                     Return this month%d second\n",mybook.getreturnnum());  
                  break;  
            }  
            case 9:  
            {  
                 mybook.PrintToLi();  
                 cout<<"-------------------------------------------------------------------------------------------------------------------"<<endl;  
                 break;  
            }  
            }  
        }  
        while (cho<10);  
        break;  
       // mybook.Save();  
    }  
    case 2:  
    {  
        int bh,cho,k;  
        cout<<"Please enter your reader number:\n";  
        cin>>bh;  
        if(mybook.SerchStudent(bh)==-1)  
        {  
            int n;  
            cout<<"You are not a reader of this system. Are you registered?\n";  
            cout<<"                    1.register\n";  
            cout<<"                    2.I'll think about it again\n";  
            cin>>n;  
            student temp;  
            if(n==1)  
            {  
                cout<<"Please enter your name.:";  
                cin>>temp.name;  
                cin.clear();  
                cin.sync();  
                temp.id=mybook.GetStudent();  
                temp.borrowsum=0;  
                temp.number=0;  
                temp.borrowday="0000.00.00";  
                for(int i=0;i<10;i++)  
                {  
                    temp.b[i]=0;  
                }  
                mybook.AddStudent(temp);  
                mybook.Save1();  
                //Cout < < "Successful Information Preservation"> endl;  
                cout<<"                Successful registration! Please remember your reader number. If you forget, please contact the administrator.!\n";  
                cout<<"                Full name:"<<temp.name<<endl;  
                cout<<"                Reader number:"<<temp.id<<endl;  
                k=temp.id;  
            }  
            else  
                break;  
        }  
        else  
        {  
            k=bh;  
        }  
        do  
        {  
            //Cout < < welcome to use the library management system > endl;  
            cin.clear();  
            cin.sync();  
            //system("cls");  
            cout<<"              1.All book catalogues "<<endl;  
            cout<<"              2.Query books "<<endl;  
            cout<<"              3.Return books "<<endl;  
            cout<<"              4.Book reservation"<<endl;  
            cout<<"              5.Check out my borrowing information "<<endl;  
          //  cout<<"  
            cout<<"              6.Sign out "<<endl;  
            cout<<"              Please select the function,Input instruction "<<endl;  
            cin>>cho;  
            switch(cho)  
            {  
            case 1:  
            {  
                int cho2;  
                do  
                {  
                    mybook.ShowAllBook();  
                    cout<<"-------------------------------------------------------------------------------------------------------------------------------------------------------------"<<endl;  
                    cout<<"0:Sort by borrowing amount , 1:Sort by index number ,3:Sign out"<<endl;  
                    cin>>cho2;  
                    switch(cho2)  
                    {  
                    case 0:  
                        mybook.SortBook(0);  
                        break;  
                    case 1:  
                        mybook.SortBook(1);  
                        break;  
                    }  
                }  
                while (cho2<2);  
                break;  
            }  
            case 2:  
            {  
                cout<<"              1.Search by title "<<endl;  
                cout<<"              2.Query by author "<<endl;  
                cout<<"              3.Query by category "<<endl;  
                cout<<"              4.Search by title and author "<<endl;  
                cout<<"              5.Sign out "<<endl;  
                cout<<"              Please select the function,Input instruction "<<endl;  
                int cho3;  
                do  
                {  
                    string Name,AutHor,Kind;  
                    cin>>cho3;  
                    switch(cho3)  
                    {  
                    case 1:  
                        cout<<"Please enter the title of the book!"<<endl;  
                        cin>>Name;  
                        mybook.SearchBookPosWithname(Name); //Search by title  
                        break;  
                    case 2:  
                        cout<<"Please enter the author!"<<endl;  
                        cin>>AutHor;  
                        mybook.SearchBookPosWithAuthor(AutHor);//Query by author  
                        break;  
                    case 3:  
                        cout<<"Please enter the category!"<<endl;  
                        cin>>Kind;  
                        mybook.SearchBookPosWithKind(Kind);//Query by category  
                        break;  
                    case 4:  
                        cout<<"Please enter the author and title!"<<endl;  
                        cin>>AutHor>>Name;  
                        mybook.SearchBookPosWithAB(AutHor,Name);//Search by author and title  
                        break;  
                    }  
                }  
                while(cho3<=4&&cho3>=1);  
                break;  
            }  
            case 3:         //Return books  
            {  
                string bookname,bookauthor;  
                cout<<"Please enter the title and author of the book to be returned:"<<endl;  
                cin>>bookname>>bookauthor;  
                mybook.BackBook(bookname,bookauthor,k);  
                break;  
            }  
            case 4://Book reservation  
            {  
                  string bookname,author;  
                  cout<<"Please enter the title and author of the book you want to make an appointment with.:"<<endl;  
                  cin>>bookname>>author;  
                  mybook.Appointment(bookname,author);//Book reservation  
                  break;  
            }  
            case 5://Access to personal information  
            {  
                //mybook.SortStudent(1);  
                cout<<setw(8)<<"Reader number"<<setw(8)<<"Full name"<<setw(14)<<"History borrowing times"<<setw(18)<<"Number of books borrowed now"<<setw(14)<<"Last Return Time"<<endl;  
                mybook.PrintStudent(k);  
                mybook.SortStudent(0);  
                printf("You rank No. 1 in the total number of readers borrowed %d position\n",mybook.SerchStudent(k)+1);  
                printf("The maximum borrowing volume of all readers is:%d second\n",mybook.readsum(1));  
                mybook.SortStudent(1);  
                cout<<"-------------------------------------------------------------------------------------------------------------------"<<endl;  
                break;  
            }  
            }  
        }  
        while (cho<6);  
        break;  
    }  
   }  
   mybook.Save();  
   mybook.Save1();  
   return 0;  
}  

Posted by True`Logic on Sat, 30 Mar 2019 14:48:30 -0700