Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. #include "BookCollection.h"
  2. #include "bookdata.h"
  3. //#include "bookinfo.h"
  4. #include <iostream>
  5. #include <string>
  6. #include <cctype>
  7.  
  8. int BookCollection::findBook(string isbntitle)
  9. {
  10. int index=0;
  11. string x, y;
  12. for (index=0; index < 20; index++)
  13. {
  14. x = book[index].getTitle();
  15. y = book[index].getIsbn();
  16. if (isbntitle == x || isbntitle == y)
  17. return index;
  18. else
  19. return -1;
  20. }
  21. }
  22. void BookCollection::addBook()
  23. {
  24. bool empt;
  25. for (int i=0; i < MAX_BOOKS; i++)
  26. {
  27. empt = book[i].isEmpty();
  28. if (empt)
  29. {
  30. book[i].isEmpty(false);
  31. cout << "Book Title: ";
  32. string title;
  33. cin.ignore();
  34. getline(cin, title);
  35. book[i].setTitle(title);
  36. cout << "ISBN: ";
  37. string isbn;
  38. cin >> isbn;
  39. book[i].setIsbn(isbn);
  40. cout << "Author's Name: ";
  41. string author;
  42. cin.ignore();
  43. getline(cin, author);
  44. book[i].setAuthor(author);
  45. cout << "Publisher's Name: ";
  46. string publisher;
  47. cin.ignore();
  48. getline(cin, publisher);
  49. book[i].setPub(publisher);
  50. cout << "Date book was added to inventory: ";
  51. string date;
  52. cin >> date;
  53. book[i].setDateAdded(date);
  54. cout << "Quantity being added: ";
  55. int qty;
  56. cin >> qty;
  57. book[i].setQty(qty);
  58. cout << "Wholesale price: ";
  59. double wholesale;
  60. cin >> wholesale;
  61. book[i].setWholesale(wholesale);
  62. cout << "Retail price: ";
  63. double retail;
  64. cin >> retail;
  65. book[i].setRetail(retail);
  66. break;
  67. }
  68. else
  69. {
  70. cout << "There are no empty places!\n";
  71. }
  72. }
  73. }
  74. void BookCollection::deleteBook()
  75. {
  76. char verify;
  77. int checker;
  78. string inputinfo;
  79. cout << "\nEnter book title or ISBN: ";
  80. cin.ignore();
  81. getline(cin, inputinfo);
  82. checker = findBook(inputinfo);
  83. if (checker == -1)
  84. {
  85. cout << "Book was not in the inventory" << endl;
  86. }
  87. else
  88. {
  89. book[checker].bookInfo();
  90. }
  91. cout << "Is this the book you want to delete? [Y/N]: ";
  92. cin >> verify;
  93. if (verify == 'N')
  94. {
  95. cout << "You have chosen not to delete" << endl;
  96. }
  97. else if (verify == 'Y')
  98. {
  99. book[checker].removeBook(true);
  100. }
  101. }
  102. void BookCollection::editBook()
  103. {
  104. string author, isbn, title, publisher, dateAdded, userInput;
  105. double wholesale, retail;
  106. int qty, location;
  107.  
  108. cout << "\nEnter book title or ISBN: ";
  109. cin.ignore();
  110. getline(cin, userInput);
  111. location = findBook(userInput);
  112. isbn = book[location].getIsbn();
  113. title = book[location].getTitle();
  114. author = book[location].getAuthor();
  115. publisher = book[location].getPub();
  116. dateAdded = book[location].getDateAdded();
  117. qty = book[location].getQty();
  118. wholesale = book[location].getWholesale();
  119. retail = book[location].getRetail();
  120. if (location == -1)
  121. cout << "\nBook not in the system!" << endl;
  122. else
  123. {
  124. int choice;
  125. do
  126. {
  127. cout << "1) ISBN: " << isbn << endl;
  128. cout << "2) Title: " << title << endl;
  129. cout << "3) Author: " << author << endl;
  130. cout << "4) Publisher: " << publisher << endl;
  131. cout << "5) Date Added: " << dateAdded << endl;
  132. cout << "6) Quantity-on-Hand: " << qty << endl;
  133. cout << "7) Wholesale Cost: " << wholesale << endl;
  134. cout << "8) Retail Price: " << retail << endl;
  135. cout << "9) Go back." << endl;
  136. cout << "\tWhich field would you like to edit?: ";
  137. cin >> choice;
  138. if (choice == 1)
  139. {
  140. string newIsbn;
  141. cout << "\nEnter ISBN: ";
  142. cin.ignore();
  143. getline(cin, newIsbn);
  144. book[location].setIsbn(newIsbn);
  145. isbn = book[location].getIsbn();
  146. }
  147. if (choice == 2)
  148. {
  149. string newTitle;
  150. cout << "\nEnter Title: ";
  151. cin.ignore();
  152. getline(cin, newTitle);
  153. book[location].setTitle(newTitle);
  154. title = book[location].getTitle();
  155. }
  156. if (choice == 3)
  157. {
  158. string newAuthor;
  159. cout << "\nEnter Author: ";
  160. cin.ignore();
  161. getline(cin, newAuthor);
  162. book[location].setAuthor(newAuthor);
  163. author = book[location].getAuthor();
  164. }
  165. if (choice == 4)
  166. {
  167. string newPub;
  168. cout << "\nEnter Publisher: ";
  169. cin.ignore();
  170. getline(cin, newPub);
  171. book[location].setPub(newPub);
  172. publisher = book[location].getPub();
  173. }
  174. if (choice == 5)
  175. {
  176. string newDate;
  177. cout << "\nEnter date added: ";
  178. cin.ignore();
  179. getline(cin, newDate);
  180. book[location].setDateAdded(newDate);
  181. dateAdded = book[location].getDateAdded();
  182. }
  183. if (choice == 6)
  184. {
  185. int newQty;
  186. cout << "\nEnter quantity on-hand: ";
  187. cin >> newQty;
  188. book[location].setQty(newQty);
  189. qty = book[location].getQty();
  190. }
  191. if (choice == 7)
  192. {
  193. double newWholesale;
  194. cout << "\nEnter wholesale price: ";
  195. cin >> newWholesale;
  196. book[location].setWholesale(newWholesale);
  197. wholesale = book[location].getWholesale();
  198. }
  199. if (choice == 8)
  200. {
  201. double newRetail;
  202. cout << "\nEnter retail price: ";
  203. cin >> newRetail;
  204. book[location].setRetail(newRetail);
  205. retail = book[location].getRetail();
  206. }
  207. }
  208. while (choice != 9);
  209. }
  210. }
  211. void BookCollection::lookUpBook()
  212. {
  213. string userInput;
  214. int location;
  215. cout << "\nEnter book title or ISBN: ";
  216. cin.ignore();
  217. getline(cin, userInput);
  218. location = findBook(userInput);
  219. if (location == -1)
  220. cout << "\nBook not in the system!" << endl;
  221. else
  222. {
  223. book[location].bookInfo();
  224. }
  225. }
  226. int BookCollection::lookupIsbn(string isbn)
  227. {
  228. int location;
  229. location = findBook(isbn);
  230. if (location == -1)
  231. cout << "\nBook not in the system!" << endl;
  232. else
  233. {
  234. book[location].bookInfo();
  235. }
  236. }
  237. bool BookCollection::booksAvailable()
  238. {
  239. int i = 0, bAvail = 0;
  240. bool check;
  241. while(i < MAX_BOOKS)
  242. {
  243. check = book[i].isEmpty();
  244. if(check)
  245. {
  246. i++;
  247. }
  248. else
  249. {
  250. bAvail++;
  251. i++;
  252. }
  253. }
  254. if(bAvail == 0)
  255. {
  256. cout << "There are no books available" << endl;
  257. return false;
  258. }
  259. else
  260. {
  261. return true;
  262. }
  263. }
  264. void BookCollection::repListing()
  265. {
  266. char cont;
  267. cout << "\nInventory Listing" << endl;
  268. int count = 0;
  269. cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Author\t" << "Publisher\t" << "Date Added " << "Quantity "
  270. << " Wholesale " << " Retail " << endl;
  271. while(count < MAX_BOOKS)
  272. {
  273. cout << book[count].getTitle() << book[count].getIsbn() << book[count].getAuthor()
  274. << book[count].getPub() << book[count].getDateAdded() << book[count].getQty()
  275. << book[count].getWholesale() << book[count].getRetail() << endl;
  276. count++;
  277. }
  278. cout << "Press enter to continue" << endl;
  279. cin >> cont;
  280. return;
  281. }
  282. void BookCollection::repWholesale()
  283. {
  284. char cont;
  285. cout << "\nInventory Wholesale Value" << endl;
  286. int count = 0;
  287. double total = 0;
  288. cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Wholesale\t" << endl;
  289. while(count < MAX_BOOKS)
  290. {
  291. cout << book[count].getTitle() << book[count].getIsbn() << book[count].getQty()
  292. << book[count].getWholesale() << endl;
  293. total = total + (book[count].getQty() * book[count].getWholesale());
  294. count++;
  295. }
  296. cout << "The Total Wholesale Value of the Inventory is $" << total << endl;
  297. cout << "Press enter to continue" << endl;
  298. cin >> cont;
  299. return;
  300. }
  301. void BookCollection::repRetail()
  302. {
  303. char cont;
  304. cout << "\nInventory Retail Value" << endl;
  305. int count = 0;
  306. double total = 0;
  307. cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Retail\t" << endl;
  308. while(count < MAX_BOOKS)
  309. {
  310. cout << book[count].getTitle() << book[count].getIsbn() << book[count].getQty()
  311. << book[count].getRetail() << endl;
  312. total = total + (book[count].getQty() * book[count].getRetail());
  313. count++;
  314. }
  315. cout << "The Total Retail Value of the Inventory is $" << total << endl;
  316. cout << "Press enter to continue" << endl;
  317. cin >> cont;
  318. return;
  319. }
  320. void BookCollection::repQty()
  321. {
  322. int i, x, y;
  323. BookData temp;
  324. bool swap = true;
  325. char cont;
  326. cout << "\nListing by Quantity." << endl;
  327. while(swap)
  328. {
  329. swap = false;
  330. for(i = 0; i < MAX_BOOKS -1; i++)
  331. {
  332. x = book[i].getQty();
  333. y = book[i + 1].getQty();
  334. if(x < y)
  335. {
  336. temp = book[i];
  337. book[i] = book[i + 1];
  338. book[i + 1] = temp;
  339. swap = true;
  340. }
  341. }
  342. }
  343. i = 0;
  344. cout << "Title\t" << "ISBN\t" << "Quantity" << endl;
  345. while(i < MAX_BOOKS)
  346. {
  347. cout << book[i].getTitle() << "\t" << book[i].getIsbn() << "\t" << book[i].getQty() << endl;
  348. }
  349. cout << "Press enter to continue" << endl;
  350. cin >> cont;
  351. return;
  352. }
  353. void BookCollection::repCost()
  354. {
  355. cout << "\nListing by Cost." << endl;
  356. int i;
  357. double x, y;
  358. char cont;
  359. BookData temp;
  360. bool swap = true;
  361. while(swap)
  362. {
  363. swap = false;
  364. for(i = 0; i < MAX_BOOKS -1; i++)
  365. {
  366. x = book[i].getWholesale();
  367. y = book[i+1].getWholesale();
  368. if(x < y)
  369. {
  370. temp = book[i];
  371. book[i] = book[i + 1];
  372. book[i + 1] = temp;
  373. swap = true;
  374. }
  375. }
  376. }
  377. i = 0;
  378. cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Wholesale" << endl;
  379. while(i < MAX_BOOKS)
  380. {
  381. cout << book[i].getTitle() << "\t" << book[i].getIsbn() << "\t" << book[i].getQty() << "\t" << book[i].getWholesale() << endl;
  382. }
  383. cout << "Press enter to continue" << endl;
  384. cin >> cont;
  385. return;
  386. }
  387. void BookCollection::repAge()
  388. {
  389. cout << "\nListing by Age." << endl;
  390. int i;
  391. char cont;
  392. string x, y;
  393. BookData temp;
  394. bool swap = true;
  395. while(swap)
  396. {
  397. swap = false;
  398. for(i = 0; i < MAX_BOOKS -1; i++)
  399. {
  400. x = book[i].getDateAdded();
  401. y = book[i].getDateAdded();
  402. if(x < y)
  403. {
  404. temp = book[i];
  405. book[i] = book[i + 1];
  406. book[i + 1] = temp;
  407. swap = true;
  408. }
  409. }
  410. }
  411. i = 0;
  412. cout << "Title\t" << "ISBN\t" << "Quantity\t" << "Date Added" << endl;
  413. while(i < MAX_BOOKS)
  414. {
  415. cout << book[i].getTitle() << "\t" << book[i].getIsbn() << "\t" << book[i].getQty() << "\t" << book[i].getDateAdded() << endl;
  416. }
  417. cout << "Press enter to continue" << endl;
  418. cin >> cont;
  419. return;
  420. }
  421. /*
  422. void match(string title, BookData b[])
  423. {
  424. for(int i=0; i < title.length(); i++)
  425. {
  426. title[i] = toupper(title[i]);
  427. }
  428. }
  429. */
Add Comment
Please, Sign In to add comment