Sie sind auf Seite 1von 6

#include<iostream>//CORRECT CODE #include<string.h> #include<conio.

h> #include<fstream> #define MAX 20 using namespace std; class MEMBER; void introduction() { cout<<"\n\n\t\tYou can search your books using this application\n"; } class OPAC { struct bk_node { string book_name; string author; int copies; double price; string publi; bk_node *left; bk_node *right; bk_node (string bk_nm,string authr,int cp,double cost,string public a,bk_node *l,bk_node *r):book_name(bk_nm),author(authr),copies(cp),price(cost),p ubli(publica),left(l),right(r){} }; bk_node *root; public: OPAC(string bk_nm,string authr,int cp,double price,string publi){root=new bk_node(bk_nm,authr,cp,price,publi,NULL,NULL);} ~OPAC(){makeempty(root);} private: void search_by_author(const string &author,bk_node *&t) { while(t!=NULL) { if(author!=t->author)//NOT WORKING PROPERLY!!!! { cout<<"NO SUCH BOOK IS FOUND IN THE LIBRARY \n"; //break; } if(author>t->author) t=t->right; else if(author<t->author) t=t->left; else if(author==t->author) { cout<<"Book name: "<<t->book_name<<endl; cout<<"Author name: "<<t->author<<endl; if(t->copies>0) cout<<"BOOK IS AVAILABLE\nAVAILABLE="<< t->copies<<endl<<endl; else cout<<"NO BOOK IS AVAILABLE\n"; break; } /*else if(author!=t->author)//NOT WORKING PROPE RLY!!!!

{ cout<<"NO SUCH BOOK IS FOUND IN THE LIBRARY \n"; break; } */ } } void search(const string &bk_srch,bk_node *&t ) { while(t!=NULL) { if(bk_srch>t->book_name) t=t->right; else if(bk_srch<t->book_name) t=t->left; else if(bk_srch==t->book_name) { cout<<"Book name: "<<t->book_name<<endl; cout<<"Author name: "<<t->author<<endl; if(t->copies>0) cout<<"BOOK IS AVAILABLE\nAVAILABLE="<< t->copies<<endl; else cout<<"BOOK IS NOT AVAILABLE\n"<<endl; break; } else//NOT WORKING PROPERLY!!!! { cout<<"NO SUCH BOOK IS FOUND IN THE LIBRARY \n"; break; } } } void makeempty(bk_node *&t) { if(t!=NULL) { makeempty(t->left); makeempty(t->right); delete t; } t=NULL; } void print(bk_node *&t) { if(t!=NULL) { cout<<"BOOK NAME::"<<t->book_name<<endl; cout<<"AUTHOR::"<<t->author<<endl; cout<<"COPIES::"<<t->copies<<endl; cout<<"PRICE::"<<t->price<<endl; cout<<"PUBLICATION::"<<t->publi<<endl<<endl; print(t->left); print(t->right); } else

return; } void insert( string bk_nm,string authr,int cp,double price,string publi,bk_node *&t) { if(t==NULL) t=new bk_node(bk_nm,authr,cp,price,publi,NULL,NULL); else if(bk_nm<t->book_name) insert(bk_nm,authr,cp,price,publi,t->left); else if(bk_nm>t->book_name) insert(bk_nm,authr,cp,price,publi,t->right); else; } public: void search_bk() { cout<<"Enter the book name for checking its availability\n"; string bk_srch; cin>>bk_srch; search(bk_srch,root); } void search_by_author() { cout<<"Enter the author name\n"; string author; cin>>author; search_by_author(author,root); } void insert_file_bk() { const int N=80; char line[N]; char *cp; double price; string bk,aut,publi; ifstream fin; int ctr=1; int cpy; fin.open("bk_file.txt"); while(fin) { fin.getline(line,N); if(ctr==1) bk=line; if(ctr==2) aut=line; if(ctr==3) cpy = atoi(line); if(ctr==4) price=atof(line); if(ctr==5) { publi=line; insert(bk,aut,cpy,price,publi,root); ctr=0; } ctr++;

} fin.close(); } void insert_bk() { ofstream fout; fout.open("bk_file.txt",ios::app); double price; string bk_nm,author_nm,publi; int bk_code,bk_cp,bk_price; cout<<"Enter the book name\n"; cin>>bk_nm; cout<<"Enter the author name\n"; cin>>author_nm; cout<<"Enter the no of copies\n"; cin>>bk_cp; cout<<"Enter the price\n"; cin>>price; cout<<"Enter the publication\n"; cin>>publi; fout<<bk_nm<<endl; fout<<author_nm<<endl; fout<<bk_cp<<endl; fout<<price<<endl; fout<<publi<<endl; fout.close(); insert(bk_nm,author_nm,bk_cp,price,publi,root); } void display() { print(root); } }; void welcome() { cout<<"\n\n\t\tWELCOME TO THE LIBRARY'S OPAC MANAGEMENT\n\n"; } void ADMIN_MAIN_MENU() { OPAC bk_obj("JAVA","weiss",9,45.5,"Pearson"); bk_obj.insert_file_bk(); char ch; while(1){ cout <<"\n\n\tL I B R A Y' S O P A C M A N A G E M E N T"<<endl ; cout <<"\t~~~~~~~~~~~~~~~~~~~~~~"<<endl ; cout <<"\t1. ADD NEW BOOK"<<endl ; cout <<"\t2. LIST OF BOOKS" <<endl; cout <<"\t3. SEARCH BY AUTHORS" <<endl; cout<<"\t4. SEARCH BOOKS"<<endl; cout <<"\t0. QUIT" <<endl; cout <<"\tEnter your choice : "<<endl ; ch = getche() ; system("cls"); if (ch == 27) break ;

else if (ch == '1') { bk_obj.insert_bk(); } else if (ch == '2') { bk_obj.display(); } else if(ch=='3') { bk_obj.search_by_author(); } else if (ch == '4') bk_obj.search_bk(); if (ch == '0') break ; } } void USER_MAIN_MENU() { OPAC bk_obj("JAVA","weiss",9,45.5,"Pearson"); bk_obj.insert_file_bk(); char ch; while(1){ cout <<"\n\n\tL I B R A Y' S O P A C M A N A G E M E N T"<<endl ; cout <<"\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl ; cout <<"\t1. LIST OF BOOKS" <<endl; cout <<"\t2. SEARCH BOOK" <<endl; cout<<"\t3. SEARCH BY AUTHOR"<<endl; cout <<"\t0. QUIT" <<endl; cout <<"\tEnter your choice : "<<endl ; ch = getche() ; system("cls"); if (ch == 27) break ; else if (ch == '1') { bk_obj.display(); } else if (ch == '2') bk_obj.search_bk(); else if(ch=='3') bk_obj.search_by_author(); if (ch == '0') break ; } } int main() { welcome(); cout<<"\t\tADMIN OR USER"<<endl; cout<<"\t\tENTER THE PASSWORD\n";

string password; cin>>password; if(password=="admin") ADMIN_MAIN_MENU(); else { introduction(); USER_MAIN_MENU(); } getch(); return 0; }

Das könnte Ihnen auch gefallen