//*************************************************************// retrieve_system.h implemention file--retrieve_system.cpp//************************************************************** #ifndef RETRIEVE_SYSTEM_H_#define RETRIEVE_SYSTEM_H_#include"book_tree.h"#include"book_exception.h"class retrieveSys{public:retrieveSys();void retrieve(const bookTree &treePtr)const throw(bookException);};#endif
//*************************************************************// retrieve_system.cpp inquiring the books' information//************************************************************** #include"retrieve_system.h"#include<cstdlib>retrieveSys::retrieveSys(){}void retrieveSys::retrieve(const bookTree &treePtr)const throw(bookException){char ch;system("cls");cout<<"********************************************************************************"<<endl;cout<<"********************************************************************************\n"<<endl; cout<<"********** Please select retrieving manner **********\n"<<endl;cout<<"********** T or t for Title **********"<<endl;cout<<"********** A or a for Author **********"<<endl;cout<<"********** I or i for ISBN **********"<<endl;cout<<"********** P or p for Publisher **********"<<endl;cout<<"********** C or c for category **********"<<endl;cout<<"********** Q or q for Quit **********\n"<<endl;cout<<"********************************************************************************"<<endl;cout<<"********************************************************************************"<<endl;cout<<"\t\t\tretrieving manner :";cin>>ch;while(cin.get()!='\n');cout<<endl;while(ch!='Q'&&ch!='q'){if(ch=='T'||ch=='t'){cout<<"\t\t\tenter the book's title :";string _title;getline(cin,_title);treePtr.search(_title,ch);} else if(ch=='A'||ch=='a'){cout<<"\t\t\tenter the book's author :";string _title;getline(cin,_title);treePtr.search(_title,ch);}else if(ch=='I'||ch=='i'){cout<<"\t\t\tenter the book's ISBN :";string _title;getline(cin,_title);treePtr.search(_title,ch);}else if(ch=='P'||ch=='p'){cout<<"\t\t\tenter the book's publisher :";string _title;getline(cin,_title);treePtr.search(_title,ch);}else if(ch=='C'||ch=='c'){cout<<"\t\t\tenter the book's category :";string _title;getline(cin,_title);treePtr.search(_title,ch);}elsecout<<"\t\t\tyou should input a right manner !"<<endl;while(cin.get()!='\n'); system("pause"); system("cls"); cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************\n"<<endl; cout<<"********** Please select retrieving manner **********\n"<<endl; cout<<"********** T or t for Title **********"<<endl; cout<<"********** A or a for Author **********"<<endl; cout<<"********** I or i for ISBN **********"<<endl; cout<<"********** P or p for Publisher **********"<<endl; cout<<"********** C or c for category **********"<<endl; cout<<"********** Q or q for Quit **********\n"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************"<<endl; cout<<"\t\t\tretrieving manner :"; cin>>ch; while(cin.get()!='\n') ; cout<<endl;}}
//*********************************************************************// return_system.h implemention file--reuturn_system.cpp//******************************************************************** #ifndef RETURN_SYSTEM_H_#define RETURN_SYSTEM_H_#include<string>#include<fstream>#include<iostream>#include"book_tree.h"#include"customer_tree.h"using namespace std;class returnSys{private:string name;string password;public:returnSys();void createAccount();string getName()const;string getPassword()const;void setPassword(const string &_password);void revert(bookTree &btree,customerTree &ctree)throw(bookException,customerException);friend ofstream &operator<<(ofstream &fout,const returnSys &_sys);friend ifstream &operator>>(ifstream &fin,returnSys &_sys);};#endif
//****************************************************************// return_sytem.cpp managing returning books task//****************************************************************#include"return_system.h"#include<cstdlib>returnSys::returnSys(){name="";password="";}void returnSys::createAccount(){cout<<"\t\t Create a new returning Admin account "<<endl;cout<<"\n\t\t\tenter Admin's name :";getline(cin,name);cout<<endl;bool isok=false;string _password;while(!isok){ cout<<"\t\t\tenter Admin's password :"; getline(cin,_password); cout<<"\n\t\t\tenter Admin's password again :"; getline(cin,password); if(password!=_password) { cout<<"\t\t\t\a\a\aenter the password wrong !enter once more "<<endl; } else isok=true; }cout<<"\n\t\t\tcreat new Admin account success !"<<endl;}string returnSys::getName()const{return name;}string returnSys::getPassword()const{return password;}void returnSys::setPassword(const string &_password){password=_password;}ofstream &operator<<(ofstream &fout,const returnSys &_sys){fout<<_sys.name<<'~'<<_sys.password<<'~'<<endl;return fout;}ifstream &operator>>(ifstream &fin,returnSys &_sys){getline(fin,_sys.name,'~');getline(fin,_sys.password,'~');while(fin.get()!='\n');return fin;}void returnSys::revert(bookTree &btree,customerTree &ctree)throw(bookException ,customerException){system("cls");cout<<"********************************************************************************\n"<<endl;cout<<"\t\t\tenter Admin's name :";string _name; getline(cin,_name);cout<<"\t\t\tenter Admin's password :";string _password; getline(cin,_password);cout<<endl;if(_name==name&&_password==password){cout<<"\t\t\t\tlogin success !"<<endl;cout<<"********************************************************************************"<<endl;bool cb=false;char ch;while(!cb){cout<<"\t\t\tenter the book's ISBN :";string _isbn;getline(cin,_isbn);try{ string _ID=btree.search(_isbn).getCustID(); try{ customerItem &citem =ctree.search(_ID);citem.display(); citem.revert(_isbn); cout<<"\t\t\t return the book success ! "<<endl; cout<<"\t is somebody continue( Y for continue and N for Exit):"; cin>>ch; while(cin.get()!='\n') ; if(ch=='Y'||ch=='y') cb=false; else cb=true; }catch(customerException &cexcept) { throw; } }catch(bookException &bexcept){throw;}catch(customerException &cexcept){throw;}}}elsecout<<"\t\t name or password is wrong .Login failed !"<<endl;}
//*******************************************************************// borrow_system.h implemention file--borrow_system.cpp//*******************************************************************#ifndef BORROW_SYSTEM_H_#define BORROW_SYSTEM_H_#include<string>#include<iostream>#include<fstream>#include"book_tree.h"#include"customer_tree.h"using namespace std;class borrowSys{private:string name;string password;public:borrowSys();void createAccount();string getName()const;string getPassword()const;void setPassword(const string &_password);void borrow(bookTree &btree,customerTree &ctree)throw(bookException,customerException);friend ofstream &operator<<(ofstream &fout,const borrowSys &_sys);friend ifstream &operator>>(ifstream &fin,borrowSys &_sys);};#endif
//***************************************************************// borrow_system.cpp managing borrowing books task//*****************************************************************#include"borrow_system.h"#include"book_tree.h"#include"book_item.h"#include"customer_item.h"#include"customer_tree.h"#include<cstdlib>borrowSys::borrowSys(){name="";password="";}void borrowSys::createAccount(){cout<<"\t\t Create a new borrowing Admin account "<<endl<<endl;cout<<"\t\t\tenter Admin's name :";getline(cin,name);cout<<endl;bool isok=false;string _password;while(!isok){cout<<"\t\t\tenter Admin's password :";getline(cin,_password);cout<<"\n\t\t\tenter Admin's password again :";getline(cin,password);if(password!=_password){cout<<" \t\t\a\a\aenter the password wrong ! enter once more "<<endl;}elseisok=true;}cout<<"\n\t\t\tcreat new Admin account success !"<<endl;}string borrowSys::getName()const{return name;}string borrowSys::getPassword()const{return password;}void borrowSys::setPassword(const string &_password){password=_password;}ofstream &operator<<(ofstream &fout,const borrowSys &_sys){fout<<_sys.name<<'~'<<_sys.password<<'~'<<endl;return fout;}ifstream &operator>>(ifstream &fin,borrowSys &_sys){getline(fin,_sys.name,'~');getline(fin,_sys.password,'~');while(fin.get()!='\n');return fin;}void borrowSys::borrow(bookTree &btree,customerTree &ctree)throw(bookException,customerException){system("cls");cout<<"********************************************************************************\n"<<endl;cout<<"\t\t\tenter Admin's name :";string _name;getline(cin,_name);cout<<"\n\t\t\tenter Admin's password :";string _password;getline(cin,_password);cout<<endl;if(_name==name&&_password==password){cout<<"\t\t\t\tlogin success !"<<endl;cout<<"******************************************************************************************\n"<<endl;bool cb=false;char ch;while(!cb){cout<<"\t\t\tenter customer's ID :";string _ID;getline(cin,_ID);cout<<endl;try{ customerItem &citem=ctree.search(_ID); citem.display(); cout<<"--------------------------------------------------------------------------------\n"<<endl; bool cont=false; char man; while(!man) { cout<<"\t\t\tenter the book's ISBN :"; string _isbn; getline(cin,_isbn); cout<<endl; try { bookItem &bitem=btree.search(_isbn); bitem.display(); try { citem.borrow(bitem); cout<<"\t\t\t\tborrow success!"<<endl; cout<<"\t do you want to continue( Y for continue and N for Exit):"; cin>>man; while(cin.get()!='\n') ; if(man=='Y'||man=='y') man=false; else man=true; } catch(customerException &cexcept) { throw; } } catch(customerException &cexcept) { throw; } catch(bookException &bexcept) { throw; }} }catch(customerException &cexcept){throw;}catch(bookException &bcexcept){throw;}cout<<"\t is somebody continue( Y for continue and N for Exit ):";cin>>ch;while(cin.get()!='\n');if(ch=='Y'||ch=='y')cb=false;else cb=true;}}elsecout<<" \t\t\a\aname or password is wrong .Login failed !"<<endl;}
//*******************************************************************// customer_system.h implemention file---customer_system.cpp//********************************************************************#ifndef CUSTOMER_SYSTEM_H_#define CUSTOMER_SYSTEM_H_#include"book_tree.h"#include"customer_tree.h"class customerSys{public: customerSys(); int custom(bookTree &btree,customerTree &ctree)throw(bookException,customerException);};#endif
//***********************************************************// customer_system.cpp managing customer'information task//************************************************************#include"customer_system.h"#include<cstdlib>customerSys::customerSys(){}int customerSys::custom(bookTree &btree,customerTree &ctree)throw(bookException ,customerException){system("cls");cout<<"********************************************************************************\n"<<endl;cout<<"\t\t\tenter Customer's ID :";string _id; getline(cin,_id);bool ok=false;while(!ok){ try { ok=true; customerItem &citem=ctree.search(_id);cout<<"\t\t\tenter Customer's password :"; string _password; getline(cin,_password); cout<<endl; if(_id==citem.getID()&&_password==citem.getPassword()) { cout<<"\t\t\t\t login success !"<<endl; cout<<"********************************************************************************"<<endl; citem.display(); cout<<"********************************************************************************"<<endl; cout<<"\t\t would you want to reset your password ?"<<endl; cout<<"\t\t\t Y for Yes and N for No :";char yes;cin>>yes;while(cin.get()!='\n');if(yes=='Y'||yes=='y'){string pass_word;bool _bl=true;while(_bl){cout<<"\n\t\t\tenter your new password :";getline(cin,_password);cout<<endl;cout<<"\t\t\tenter your new password again :";getline(cin,pass_word);cout<<endl;if(pass_word==_password){_bl=false;citem.setPassword(pass_word);cout<<"\n\t\t\t new password set success !"<<endl;}else{cout<<"\n\t\t\t new password set failed !"<<endl;}}}return 0; } else { cout<<"\t\t Id or password is wrong ,login failed !"<<endl; return 2; } } catch(customerException &cexcept) { cout<<"\t\t You input ID is invalid !Continue ? Y or N :";char yn;cin>>yn;while(cin.get()!='\n');if(yn=='Y'||yn=='y'){cout<<"\t\t\tenter your ID again :";getline(cin,_id);ok=false;}elsereturn 1; }}}
//**********************************************************// manage_system.h implemention file--manage_system.cpp//***********************************************************#ifndef MANAGE_SYSTEM_H_#define MANAGE_SYSTEM_H_#include<string>#include<iostream>#include<fstream>#include"book_tree.h"#include"customer_tree.h"using namespace std;void cshow(const customerItem &_item);void bshow(const bookItem &_item);class manageSys{private:string name;string password;public:manageSys();void createAccount();string getName()const;string getPassword()const;void setPassword(const string &_password);void manage(bookTree &btree,customerTree &cTree)throw(bookException,customerException);friend ofstream &operator<<(ofstream &fout,const manageSys &_sys);friend ifstream &operator>>(ifstream &fin,manageSys &_sys);};#endif
//***************************************************************// manage_system.cpp managing customers and books information //***************************************************************#include"manage_system.h"#include<cstdlib>void cshow(const customerItem &_item){_item.display();}void bshow(const bookItem &_item){_item.display();}manageSys::manageSys(){name="";password="";}void manageSys::createAccount(){cout<<"\t\t Create a new managing Admin account \n"<<endl;cout<<"\t\t\tenter Admin's name :";getline(cin,name);cout<<endl;bool isok=false;string _password;while(!isok){ cout<<"\t\t\tenter Admin's password :"; getline(cin,_password); cout<<"\n\t\t\tenter Admin's password again :"; getline(cin,password); if(password!=_password) { cout<<"\t\t\t\a\a\aenter the password wrong !enter once more "<<endl; } else isok=true; }cout<<"\t\t\tcreat new Admin account success !"<<endl;}string manageSys::getName()const{return name;}string manageSys::getPassword()const{return password;}void manageSys::setPassword(const string &_password){password=_password;}ofstream &operator<<(ofstream &fout,const manageSys &_sys){fout<<_sys.name<<'~'<<_sys.password<<'~'<<endl;return fout;}ifstream &operator>>(ifstream &fin,manageSys &_sys){getline(fin,_sys.name,'~');getline(fin,_sys.password,'~');while(fin.get()!='\n');return fin;}void manageSys::manage(bookTree &btree,customerTree &ctree)throw(bookException,customerException){system("cls");cout<<"********************************************************************************\n"<<endl;cout<<"\t\t\tenter Admin's name :";string _name; getline(cin,_name);cout<<"\t\t\tenter Admin's password :";string _password; getline(cin,_password);cout<<endl;if(_name==name&&_password==password){cout<<"\t\t\t\t login success !"<<endl;cout<<"********************************************************************************"<<endl;cout<<"********************************************************************************\n"<<endl;cout<<"********** enter entry managing project **********"<<endl;cout<<"********** A or a for Adding Customer **********"<<endl;cout<<"********** D or d for Deleting Customer **********"<<endl;cout<<"********** I or i for Inserting Book **********"<<endl;cout<<"********** R or r for Removing Book **********"<<endl;cout<<"********** T or t for Traversing Customer **********"<<endl;cout<<"********** L or l for Looking Books **********"<<endl;cout<<"********** Q or q for quiting mangement **********\n"<<endl;cout<<"********************************************************************************"<<endl;cout<<"********************************************************************************"<<endl;cout<<"\t\t\tselect managing project :";char ch;cin>>ch;while(cin.get()!='\n');while(ch!='Q'&&ch!='q'){if(ch=='A'||ch=='a'){customerItem citem;citem.createCustomerItem();citem.display();try{ctree.insert(citem);}catch(customerException &cexcep){throw;}cout<<"\t\t\t\t insert customer success !"<<endl;}else if(ch=='D'||ch=='d'){cout<<"\t\t\t\t\tenter the customer's ID :";string _id;getline(cin,_id);try{ctree.search(_id).display();}catch(customerException &cexcep){throw;}cout<<"\t\t\t delete the customer really ?"<<endl;cout<<"\t\t\t Y for yes and N for No :"<<endl;char del;cin>>del;while(cin.get()!='\n');if(del=='Y'or del=='y'){try{ctree.remove(_id);}catch(customerException &cexcept){throw;}cout<<"\t\t\t delete customer success !"<<endl;}elsecout<<"\t\t\t \a\a\adelete customer failed !"<<endl;}else if(ch=='I'||ch=='i'){bookItem bitem;bitem.createBookItem();bitem.display();try{btree.insert(bitem);}catch(bookException &bExcept){throw;}cout<<"\t\t\t book insert success !"<<endl;}else if(ch=='R'||ch=='r'){ cout<<"\t\t\tenter the book's ISBN :";string _isbn;getline(cin,_isbn);try{bookItem &bitem=btree.search(_isbn);bitem.display();if(bitem.getStatus()){cout<<"\t\t\t delete the book really ?"<<endl;cout<<"\t\t\t Y for yes and N for No :"<<endl;char del;cin>>del;while(cin.get()!='\n');if(del=='Y'or del=='y'){try{btree.remove(_isbn);}catch(customerException &cexcept){throw;}cout<<"\t\t\t delete customer success !"<<endl;}elsecout<<"\t\t\t \a\a\adelete customer failed !"<<endl;}elsecout<<"\t\t\t\a\a\a\aborrowing book delete failed !"<<endl;}catch(bookException &cexcep){throw;}}else if(ch=='T'||ch=='t'){cout<<"\t\t display all the customer information "<<endl<<endl;ctree.traverse(cshow);cout<<"\t\t\t total "<<ctree.getAmount()<<" customers "<<endl<<endl;}else if(ch=='L'||ch=='l'){cout<<"\t\t display all the book information "<<endl;btree.traverse(bshow);cout<<"\t\t\t total "<<btree.getAmount()<<" books "<<endl;} cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************\n"<<endl; cout<<"********** enter entry managing project **********"<<endl; cout<<"********** A or a for Adding Customer **********"<<endl; cout<<"********** D or d for Deleting Customer **********"<<endl; cout<<"********** I or i for Inserting Book **********"<<endl; cout<<"********** R or r for Removing Book **********"<<endl; cout<<"********** T or t for Traversing Customer **********"<<endl;cout<<"********** L or l for Looking Books **********"<<endl;cout<<"********** Q or q for quiting mangement **********\n"<<endl;cout<<"********************************************************************************"<<endl;cout<<"********************************************************************************"<<endl;cout<<"\t\t\tselect managing project :"; cin>>ch; while(cin.get()!='\n') ;}}elsecout<<"\t\t \a\a\aname or password is wrong .Login failed !"<<endl;}
//*******************************************************************// library_management_system.cpp main() function // library system operating interface//******************************************************************#include"borrow_system.h"#include"customer_system.h"#include"manage_system.h"#include"retrieve_system.h"#include"return_system.h"#include<cstdlib>using namespace std;int main(){cout<<endl;cout<<endl<<endl<<endl<<endl;cout<<" \t\twelecome to use the library management system "<<endl; cout<<endl<<endl<<endl;int numb_book,numb_customer;ifstream fin("bookandcustomernumbers.txt");if(fin.is_open())fin>>numb_book>>numb_customer;elsenumb_book=numb_customer=0;fin.close();bookTree bData;fin.open("booktreedata.txt");if(!fin.is_open()){cout<<" \t\tthe library data is not exist ,create it !"<<endl<<endl<<endl; bool _continue=true;char ch;bookItem book;while(_continue){book.createBookItem();book.display();try{bData.insert(book);}catch(bookException &bexcept){cout<<"\t"<<bexcept.what()<<endl;}cout<<"\n\t\t\t new book insert success !"<<endl<<endl;cout<<"\t would you want to go on ? Y for Yes and N for No:";cin>>ch;while(cin.get()!='\n');if(ch=='Y'||ch=='y')_continue=true;else_continue=false;}bData.traverse(bshow);}else bData.read(fin,numb_book);fin.close(); customerTree cData; fin.open("customertreedata.txt"); if(fin.is_open()) cData.read(fin,numb_customer,bData); fin.close(); borrowSys borrowAdmin; fin.open("borrowAdminData.txt"); if(!fin.is_open()) { cout<<"\n\n\t\t borrowAdministrator is not exist ,create it !"<<endl; borrowAdmin.createAccount(); } else fin>>borrowAdmin; fin.close(); manageSys manageAdmin; fin.open("manageAdminData.txt"); if(!fin.is_open()) { cout<<"\n\n\t\t manageAdministrator is not exist,create it!"<<endl; manageAdmin.createAccount(); } else fin>>manageAdmin; fin.close(); returnSys returnAdmin; fin.open("returnAdminData.txt"); if(!fin.is_open()) { cout<<"\n\n\t\t returnAdministrator is not exist,create it!"<<endl; returnAdmin.createAccount(); } else fin>>returnAdmin; fin.close(); customerSys customerAdmin; retrieveSys retrieveAdmin; system("pause"); system("cls"); cout<<endl; cout<<endl; cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********** **********"<<endl; cout<<"********** **********"<<endl; cout<<"********** Please Select The Manner Of Sevice **********"<<endl; cout<<"********** **********"<<endl; cout<<"********** B for Borrow **********"<<endl; cout<<"********** C for Customer **********"<<endl; cout<<"********** R for Revert **********"<<endl; cout<<"********** I for Inquire **********"<<endl; cout<<"********** M for Manage **********"<<endl; cout<<"********** Q for Quit **********"<<endl; cout<<"********** **********"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********** Manner of Sevice : **********"; cout<<"\b\b\b\b\b\b\b\b\b\b\b\b\b"; char _manner; cin>>_manner; while(cin.get()!='\n') ; system("cls"); while(_manner!='Q'&&_manner!='q') { switch(_manner) { case 'B': case 'b':{ try{ borrowAdmin.borrow(bData,cData); }catch(bookException &be) { cout<<"\t"<<be.what()<<endl; } catch(customerException &ce) { cout<<"\t"<<ce.what()<<endl; } system("pause"); } break; case 'C': case 'c':customerAdmin.custom(bData,cData);system("pause");break; case 'R': case 'r':{ try{ returnAdmin.revert(bData,cData); }catch(bookException &be) { cout<<"\t"<<be.what()<<endl; } catch(customerException &ce) { cout<<"\t"<<ce.what()<<endl; } system("pause"); } break; case 'I': case 'i':{ try{ retrieveAdmin.retrieve(bData); }catch(bookException &be) { cout<<"\t"<<be.what()<<endl; } catch(customerException &ce) { cout<<"\t"<<ce.what()<<endl; } system("pause"); } break; case 'M': case 'm':{ try{ manageAdmin.manage(bData,cData); }catch(bookException &be) { cout<<"\t"<<be.what()<<endl; } catch(customerException &ce) { cout<<"\t"<<ce.what()<<endl; } system("pause"); } break; default: { cout<<" \t\t\tselect wrong command !"<<endl; cout<<"\n \t\t\t\tselect again !"<<endl; }; system("pause");break; } system("cls"); cout<<endl; cout<<endl; cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********** **********"<<endl; cout<<"********** **********"<<endl; cout<<"********** Please Select The Manner Of Sevice **********"<<endl; cout<<"********** **********"<<endl; cout<<"********** B for Borrow **********"<<endl; cout<<"********** C for Customer **********"<<endl; cout<<"********** R for Revert **********"<<endl; cout<<"********** I for Inquire **********"<<endl; cout<<"********** M for Manage **********"<<endl; cout<<"********** Q for Quit **********"<<endl; cout<<"********** **********"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************"<<endl; cout<<"********** Manner of Sevice : **********"; cout<<"\b\b\b\b\b\b\b\b\b\b\b\b\b";cin>>_manner;while(cin.get()!='\n');system("cls"); } ofstream fout("bookandcustomernumbers.txt"); fout<<bData.getAmount()<<" "<<cData.getAmount()<<endl; fout.close(); fout.open("customertreedata.txt"); cData.write(fout); fout.close(); fout.open("booktreedata.txt"); bData.write(fout); fout.close(); fout.open("borrowAdminData.txt"); fout<<borrowAdmin; fout.close(); fout.open("returnAdminData.txt"); fout<<returnAdmin; fout.close(); fout.open("manageAdminData.txt"); fout<<manageAdmin; fout.close(); cout<<"\t\t\t\t OVER !"<<endl; system("pause"); return 0;}
references:
《C++ primer》
《Data Abstraction and Problem Solving With C++》