Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "C:\Users\bhara\OneDrive\Documents\c ++ header files\std_lib_facilities.h"
- #include <conio.h>
- enum class Genre
- {
- fiction=1,nonfiction,periodical,biography,children
- };
- class Book
- {
- public:
- void show_details();
- void rent();
- void set_ISBN(string& str) {ISBN = str;}
- void set_author(string& str) {author=str;}
- void set_title(string& str){title=str;}
- void set_cpydate(string& str){cpydate=str;}
- void set_genre(Genre& genr) {gen=genr;}
- void set_checkedout(bool b) {checkedout=b;}
- string ret_ISBN() {return ISBN;}
- string ret_author() {return author;}
- string ret_title() {return title;}
- string ret_cpydate() {return cpydate;}
- Genre ret_gen(){return gen;}
- bool ret_checkedout(){return checkedout;}
- private:
- string ISBN,author,title,cpydate;
- Genre gen;
- bool checkedout{false};
- vector<Book>rack;
- };
- class Patron
- {
- public:
- Patron(): fees{0} {}
- void set_name(string& str) {name=str;}
- void set_libno(int& i){lib_cardno=i;}
- void set_fees(int &i) {fees=i;}
- string ret_name(){return name;}
- int ret_cardno(){return lib_cardno;}
- int ret_fees(){return fees;}
- void set_fee();
- private:
- string name;
- int lib_cardno,fees;
- };
- struct Transaction
- {
- Book b;
- Patron p;
- //Date d;
- };
- class Library
- {
- public:
- void set_rack(Book& b){rack.emplace_back(b);}
- void set_record(Patron& p){record.push_back(p);}
- vector<Book> ret_rack(){return rack;}
- vector<Patron> ret_record() {return record;}
- private:
- vector<Book> rack;
- vector<Patron> record;
- vector<Transaction> Trans;
- };
- bool verify_ISBN(Library& l,string& ISBN);
- void take_ISBN_details(Book& b,Library& l);
- void take_patron_details(Patron& p,Library& l);
- void rent(Library& l,Patron& p,Transaction& t);
- int main()
- {
- Book b; Library l; Patron p; Transaction t;
- int choice;
- while(true)
- {
- cout<<"Welcome to the library. "<<"\n"<<"Enter your choice(1,2,3)"<<"\n1. Enter a new book record"<<"\n2. Enter a new patron record"<<"\n3. Rent a book"<<endl;
- cin>>choice;
- cin.ignore();
- switch(choice)
- {
- case 1:
- take_ISBN_details(b,l);
- break;
- case 2:
- take_patron_details(p,l);
- break;
- case 3:
- rent(l,p,t);
- break;
- /* case 2:
- b.show_details();
- break;
- case 3:
- b.rent();
- break;
- }
- */
- }
- }
- }
- void take_ISBN_details(Book& b,Library& l)
- {
- char c;
- do
- {
- bool flag{true};
- do
- {
- string str;
- cout<<"\nEnter ISBN: ";
- getline(cin,str);
- flag=verify_ISBN(l,str); // changes needed here
- }
- while(!flag);
- if(flag)
- {
- string str; Genre gen;
- cout<<"\nISBN valid "<<endl; b.set_ISBN(str);
- cout<<"Enter author name: ";
- getline(cin,str); b.set_author(str);
- cout<<"Enter Title: ";
- getline(cin,str); b.set_title(str);
- cout<<"Enter copyright date: (dd/mm/yy)";
- getline(cin,str); b.set_cpydate(str);
- cout<<"Enter Genre(fiction,nonfiction,periodical,biography,children): ";
- cin>>str;
- if(str=="fiction") gen=Genre::fiction;
- else if(str=="nonfiction") gen=Genre::nonfiction;
- else if(str=="periodical") gen=Genre::periodical;
- else if(str=="biography") gen=Genre::biography;
- else if(str=="children") gen=Genre::children;
- b.set_genre(gen);
- l.set_rack(b);
- }
- cout<<"\nRecord updated. Enter another record?(y/n): ";
- cin>>c;
- cin.ignore();
- }
- while(c=='y');
- cout<<"Press any key to continue";
- getch();
- system("CLS");
- }
- bool verify_ISBN(Library& l,string& ISBN)
- {
- int a{0};
- //check ISBN for format error n-n-n-x
- for(int i=0; i<ISBN.size(); ++i)
- {
- if(ISBN[i]=='-') ++a;
- if(a==0 || a==1 || a==2)
- {
- if(isalpha(ISBN[i]))
- {
- cout<<"\nInvalid ISBN"<<endl;
- return false;
- break;
- }
- }
- else if(a>3)
- {
- cout<<"\nInvalid ISBN"<<endl;
- return false;
- break;
- }
- }
- if(a==0 || a==1 || a==2)
- {
- cout<<"\nInvalid ISBN"<<endl;
- return false;
- }
- // check ISBN if duplicate
- for(auto& a:l.ret_rack())
- {
- if(a.ret_ISBN() == ISBN)
- {
- cout<<"\nDuplicate ISBN";
- cout<<"Press any key to continue";
- return false;
- getch();
- system("CLS");
- }
- }
- return true;
- }
- void take_patron_details(Patron& p,Library& l)
- {
- char c;
- do
- {
- string str;
- int i;
- cout<<"Enter name: ";
- getline(cin,str);
- p.set_name(str);
- cout<<"Enter library number: ";
- cin>>i;
- p.set_libno(i);
- l.set_record(p);
- cout<<"\nRecord updated. Enter another record?(y/n): ";
- cin>>c;
- cin.ignore();
- }
- while(c=='y');
- cout<<"Press any key to continue";
- getch();
- system("CLS");
- }
- void rent(Library& l,Patron& p,Transaction& t)
- {
- string name; bool flag{false}; bool b;
- cout<<"\nEnter the book name: "; getline(cin,name);
- for(auto& a:l.ret_rack())
- {
- if(name==a.ret_title() && a.ret_checkedout() ==true)
- {
- cout<<"Book already rented out "<<endl; flag=true;
- break;
- }
- if(name==a.ret_title() && a.ret_checkedout()==false)
- {
- b=true;
- a.set_checkedout(b);
- cout<<"\nBook rented"<<endl; flag=true;
- break;
- }
- }
- if(!flag) cout<<"\nBook not found"<<endl;
- cout<<"Press any key to continue"; getch();
- system("CLS");
- }
Advertisement
Add Comment
Please, Sign In to add comment