fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class Lib
  8. {
  9. protected:
  10. string booth;
  11. char hall;
  12.  
  13. public:
  14. Lib(char hall, string booth)
  15. {
  16. this->booth = booth;
  17. this->hall = hall;
  18. }
  19. };
  20.  
  21. class Book : public Lib
  22. {
  23. string title;
  24. string author;
  25. int pages;
  26. int price;
  27.  
  28. public:
  29. Book(string title, string author, int pages, int price, char hall, string booth) : Lib(hall, booth)
  30. {
  31. this->title = title;
  32. this->author = author;
  33. this->pages = pages;
  34. this->price = price;
  35. }
  36.  
  37. string getTitle()
  38. {
  39. return title;
  40. }
  41. int getPrice()
  42. {
  43. return price;
  44. }
  45. int getPages()
  46. {
  47. return pages;
  48. }
  49. char getHall()
  50. {
  51. return hall;
  52. }
  53. string getBooth()
  54. {
  55. return booth;
  56. }
  57. string getAuthor()
  58. {
  59. return author;
  60. }
  61. };
  62.  
  63. class User
  64. {
  65. string first_name;
  66. string last_name;
  67. string email;
  68. string phone_number;
  69.  
  70. public:
  71. User(string first_name, string last_name, string email, string phone_number)
  72. {
  73. this->first_name = first_name;
  74. this->last_name = last_name;
  75. this->email = email;
  76. this->phone_number = phone_number;
  77. }
  78.  
  79. string getFirstName()
  80. {
  81. return first_name;
  82. }
  83. string getLastName()
  84. {
  85. return last_name;
  86. }
  87. string getEmail()
  88. {
  89. return email;
  90. }
  91. string getPhoneNumber()
  92. {
  93. return phone_number;
  94. }
  95. };
  96.  
  97. int main()
  98. {
  99. vector<User *> users;
  100. vector<Book *> books;
  101.  
  102. cout << "\n==================================" << endl;
  103. cout << "Welcome to \"The LighHouse Library\"" << endl;
  104. cout << "==================================\n"
  105. << endl;
  106.  
  107. int choice;
  108.  
  109. while (true)
  110. {
  111. cout << " ***Main menu***\n";
  112. cout << "1.Add new user.\n2.Add new book.\n3.View users.\n4.View available books.\n5.Buy a book.\n0.Exit!" << endl;
  113. cout << "Enter your choice: ";
  114. cin >> choice;
  115. cout << endl;
  116.  
  117. if (choice == 1)
  118. {
  119. string first, last, email, number;
  120. cout << "\nEnter your (fisrt name): ";
  121. cin >> first;
  122. cout << "Enter your (last name): ";
  123. cin >> last;
  124. cout << "Enter your (email): ";
  125. cin.ignore();
  126. getline(cin, email);
  127. cout << "Enter your (phone number): ";
  128. cin >> number;
  129.  
  130. users.push_back(new User(first, last, email, number));
  131. cout << "Welcome, " << first << " " << last << "!\n" << endl;
  132. cout << "============================================================================" << endl;
  133. }
  134.  
  135. else if (choice == 2)
  136. {
  137. string title, booth, author;
  138. int price, pages;
  139. char hall;
  140. cout << "\nEnter the book's (title): ";
  141. getline(cin, title);
  142. cout << "This book was (wrote by): ";
  143. getline(cin, author);
  144. cout << "How many (pages) does \"" << title << "\" has? ";
  145. cin >> pages;
  146. cout << "*in dollars* How much does it (costs): ";
  147. cin >> price;
  148. cout << "What (hall) and (booth) does \"" << title << "\" belongs? ";
  149. cin >> hall >> booth;
  150.  
  151. books.push_back(new Book(title, author, pages, price, hall, booth));
  152. cout << "Book added successfully.\n";
  153. cout << "============================================================================" << endl;
  154. }
  155.  
  156. else if (choice == 3)
  157. {
  158. if (users.empty())
  159. cout << "No users yet." << endl;
  160. else
  161. {
  162. sort(users.begin(), users.end());
  163. for (int i = 0; i < users.size(); ++i)
  164. {
  165. cout << (i + 1) << "." << users[i]->getFirstName()
  166. << " " << users[i]->getLastName()
  167. << " | " << users[i]->getEmail()
  168. << " | " << users[i]->getPhoneNumber() << endl;
  169. }
  170. }
  171. cout << "============================================================================" << endl;
  172. }
  173.  
  174. else if (choice == 4)
  175. {
  176. if (books.empty())
  177. cout << "No books yet." << endl;
  178. else
  179. {
  180. sort(books.begin(), books.end());
  181. for (int i = 0; i < books.size(); ++i)
  182. {
  183. cout << (i + 1) << "." << books[i]->getTitle()
  184. << " was wrote by: \"" << books[i]->getAuthor()
  185. << "\" | " << books[i]->getPages() << "pages ,"
  186. << books[i]->getPrice() << "$ | Hall:"
  187. << books[i]->getHall() << " ,Booth: "
  188. << books[i]->getBooth() << endl;
  189. }
  190. }
  191. cout << "============================================================================" << endl;
  192. }
  193.  
  194. else if (choice == 5)
  195. {
  196. int i = 1, book_number;
  197. Book *selected = books[book_number - 1];
  198. char answer;
  199. for (Book *b : books)
  200. {
  201. cout << i << "." << b->getTitle() << " ---> " << b->getPrice() << "$" << endl;
  202. i++;
  203. }
  204. cout << "*Number of the book* Which book you want to buy: ";
  205. cin >> book_number;
  206. cout << "you will pay " << selected->getPrice() << "$" << "for \"" << selected->getTitle() << "\".\n";
  207. cout << "Enter \"Y\" to confirm: ";
  208. cin >> answer;
  209. if (answer == 'Y' || answer == 'y')
  210. cout << "You bought the book!";
  211. else
  212. cout << "Miser.\n";
  213. cout << "============================================================================" << endl;
  214. }
  215.  
  216. else if (choice == 0)
  217. break;
  218. else
  219. {
  220. cout << "Invalid choice!" << endl;
  221. cout << "============================================================================" << endl;
  222. }
  223. }
  224. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
==================================
Welcome to "The LighHouse Library"
==================================

   ***Main menu***
1.Add new user.
2.Add new book.
3.View users.
4.View available books.
5.Buy a book.
0.Exit!
Enter your choice: