bharat_upmanyu

Untitled

Apr 6th, 2021
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. #include "C:\Users\bhara\OneDrive\Documents\c ++ header files\std_lib_facilities.h"
  2. #include <conio.h>
  3.  
  4.  
  5. enum class Genre
  6. {
  7. fiction=1,nonfiction,periodical,biography,children
  8. };
  9.  
  10.  
  11. class Book
  12. {
  13. public:
  14.  
  15. void show_details();
  16. void rent();
  17. void set_ISBN(string& str) {ISBN = str;}
  18. void set_author(string& str) {author=str;}
  19. void set_title(string& str){title=str;}
  20. void set_cpydate(string& str){cpydate=str;}
  21. void set_genre(Genre& genr) {gen=genr;}
  22. void set_checkedout(bool b) {checkedout=b;}
  23.  
  24.  
  25. string ret_ISBN() {return ISBN;}
  26. string ret_author() {return author;}
  27. string ret_title() {return title;}
  28. string ret_cpydate() {return cpydate;}
  29. Genre ret_gen(){return gen;}
  30. bool ret_checkedout(){return checkedout;}
  31.  
  32. private:
  33. string ISBN,author,title,cpydate;
  34. Genre gen;
  35. bool checkedout{false};
  36. vector<Book>rack;
  37. };
  38.  
  39. class Patron
  40. {
  41. public:
  42. Patron(): fees{0} {}
  43. void set_name(string& str) {name=str;}
  44. void set_libno(int& i){lib_cardno=i;}
  45. void set_fees(int &i) {fees=i;}
  46.  
  47.  
  48. string ret_name(){return name;}
  49. int ret_cardno(){return lib_cardno;}
  50. int ret_fees(){return fees;}
  51.  
  52. void set_fee();
  53. private:
  54. string name;
  55. int lib_cardno,fees;
  56. };
  57.  
  58. struct Transaction
  59. {
  60. Book b;
  61. Patron p;
  62. //Date d;
  63. };
  64.  
  65. class Library
  66. {
  67. public:
  68.  
  69. void set_rack(Book& b){rack.emplace_back(b);}
  70. void set_record(Patron& p){record.push_back(p);}
  71.  
  72. vector<Book> ret_rack(){return rack;}
  73. vector<Patron> ret_record() {return record;}
  74.  
  75.  
  76. private:
  77. vector<Book> rack;
  78. vector<Patron> record;
  79. vector<Transaction> Trans;
  80. };
  81.  
  82. bool verify_ISBN(Library& l,string& ISBN);
  83. void take_ISBN_details(Book& b,Library& l);
  84. void take_patron_details(Patron& p,Library& l);
  85. void rent(Library& l,Patron& p,Transaction& t);
  86.  
  87.  
  88.  
  89. int main()
  90. {
  91. Book b; Library l; Patron p; Transaction t;
  92. int choice;
  93. while(true)
  94. {
  95.  
  96.  
  97. 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;
  98. cin>>choice;
  99. cin.ignore();
  100. switch(choice)
  101. {
  102. case 1:
  103. take_ISBN_details(b,l);
  104. break;
  105. case 2:
  106. take_patron_details(p,l);
  107. break;
  108. case 3:
  109. rent(l,p,t);
  110. break;
  111.  
  112.  
  113. /* case 2:
  114. b.show_details();
  115. break;
  116.  
  117. case 3:
  118. b.rent();
  119. break;
  120. }
  121. */
  122. }
  123. }
  124. }
  125.  
  126. void take_ISBN_details(Book& b,Library& l)
  127. {
  128. char c;
  129. do
  130. {
  131.  
  132. bool flag{true};
  133. do
  134. {
  135. string str;
  136. cout<<"\nEnter ISBN: ";
  137. getline(cin,str);
  138. flag=verify_ISBN(l,str); // changes needed here
  139. }
  140. while(!flag);
  141.  
  142. if(flag)
  143. {
  144. string str; Genre gen;
  145. cout<<"\nISBN valid "<<endl; b.set_ISBN(str);
  146. cout<<"Enter author name: ";
  147. getline(cin,str); b.set_author(str);
  148. cout<<"Enter Title: ";
  149. getline(cin,str); b.set_title(str);
  150. cout<<"Enter copyright date: (dd/mm/yy)";
  151. getline(cin,str); b.set_cpydate(str);
  152. cout<<"Enter Genre(fiction,nonfiction,periodical,biography,children): ";
  153. cin>>str;
  154. if(str=="fiction") gen=Genre::fiction;
  155. else if(str=="nonfiction") gen=Genre::nonfiction;
  156. else if(str=="periodical") gen=Genre::periodical;
  157. else if(str=="biography") gen=Genre::biography;
  158. else if(str=="children") gen=Genre::children;
  159. b.set_genre(gen);
  160. l.set_rack(b);
  161.  
  162. }
  163. cout<<"\nRecord updated. Enter another record?(y/n): ";
  164. cin>>c;
  165. cin.ignore();
  166. }
  167. while(c=='y');
  168.  
  169.  
  170. cout<<"Press any key to continue";
  171. getch();
  172. system("CLS");
  173. }
  174.  
  175.  
  176. bool verify_ISBN(Library& l,string& ISBN)
  177. {
  178. int a{0};
  179. //check ISBN for format error n-n-n-x
  180. for(int i=0; i<ISBN.size(); ++i)
  181. {
  182. if(ISBN[i]=='-') ++a;
  183. if(a==0 || a==1 || a==2)
  184. {
  185. if(isalpha(ISBN[i]))
  186. {
  187. cout<<"\nInvalid ISBN"<<endl;
  188. return false;
  189. break;
  190. }
  191. }
  192. else if(a>3)
  193. {
  194. cout<<"\nInvalid ISBN"<<endl;
  195. return false;
  196. break;
  197. }
  198. }
  199. if(a==0 || a==1 || a==2)
  200. {
  201. cout<<"\nInvalid ISBN"<<endl;
  202. return false;
  203. }
  204.  
  205.  
  206. // check ISBN if duplicate
  207. for(auto& a:l.ret_rack())
  208. {
  209. if(a.ret_ISBN() == ISBN)
  210. {
  211. cout<<"\nDuplicate ISBN";
  212. cout<<"Press any key to continue";
  213. return false;
  214. getch();
  215. system("CLS");
  216. }
  217. }
  218. return true;
  219. }
  220.  
  221.  
  222.  
  223. void take_patron_details(Patron& p,Library& l)
  224. {
  225. char c;
  226. do
  227. {
  228. string str;
  229. int i;
  230. cout<<"Enter name: ";
  231. getline(cin,str);
  232. p.set_name(str);
  233. cout<<"Enter library number: ";
  234. cin>>i;
  235. p.set_libno(i);
  236. l.set_record(p);
  237. cout<<"\nRecord updated. Enter another record?(y/n): ";
  238. cin>>c;
  239. cin.ignore();
  240. }
  241. while(c=='y');
  242. cout<<"Press any key to continue";
  243. getch();
  244. system("CLS");
  245. }
  246.  
  247.  
  248. void rent(Library& l,Patron& p,Transaction& t)
  249. {
  250. string name; bool flag{false}; bool b;
  251. cout<<"\nEnter the book name: "; getline(cin,name);
  252. for(auto& a:l.ret_rack())
  253. {
  254. if(name==a.ret_title() && a.ret_checkedout() ==true)
  255. {
  256. cout<<"Book already rented out "<<endl; flag=true;
  257. break;
  258. }
  259. if(name==a.ret_title() && a.ret_checkedout()==false)
  260. {
  261. b=true;
  262. a.set_checkedout(b);
  263. cout<<"\nBook rented"<<endl; flag=true;
  264. break;
  265. }
  266.  
  267. }
  268. if(!flag) cout<<"\nBook not found"<<endl;
  269. cout<<"Press any key to continue"; getch();
  270. system("CLS");
  271.  
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
Advertisement
Add Comment
Please, Sign In to add comment