Guest User

Untitled

a guest
Oct 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. class Book
  6. {
  7. string surname, name;
  8. int year, count;
  9. public:
  10. Book(string surname0, string name0, int year0, int count0):
  11. surname(surname0), name(name0), year(year0), count(count0){}
  12. int getYear() { return year; }
  13. void show(void) const {
  14. cout << "Surname: " << surname << endl;
  15. cout << "Name: " << name << endl;
  16. cout << "Year: " << year << endl;
  17. cout << "Count: " << count << endl;
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. multimap<string, Book*> books;
  24. multimap<string, Book*>::iterator p;
  25. multimap<int, Book*> books2;
  26. multimap<int, Book*>::iterator k;
  27. string surname, name;
  28. int year, count;
  29. int key = 0;
  30. while(key!=5) {
  31. cout << "[1] Add book\n[2] Delete book\n\
  32. \r[3] Book sort by name\n\
  33. \r[4] Book sort by year\n[5] Exit\n>>> ";
  34. cin >> key;
  35. switch(key) {
  36. case 1:
  37. cout << "Enter author surname: ";
  38. cin >> surname;
  39. cout << "Enter book name: ";
  40. cin >> name;
  41. cout << "Enter year of book: ";
  42. cin >> year;
  43. cout << "Enter count of book: ";
  44. cin >> count;
  45. books.insert(make_pair(surname, new Book(surname, name, year, count)));
  46. break;
  47. case 2:
  48. cout << "Enter author surname: ";
  49. cin >> surname;
  50. books.erase(surname);
  51. break;
  52. case 3:
  53. for (p = books.begin(); p != books.end(); p++) {
  54. cout << "//----------------------------------------//\n";
  55. (*p).second->show();
  56. }
  57. cout << "//----------------------------------------//\n";
  58. break;
  59. case 4:
  60. for (p = books.begin(); p != books.end(); p++) {
  61. books2.insert(make_pair((*p).second->getYear(), (*p).second));
  62. }
  63. for (k = books2.begin(); k != books2.end(); k++) {
  64. cout << "//----------------------------------------//\n";
  65. (*k).second->show();
  66. }
  67. cout << "//----------------------------------------//\n";
  68. books2.clear();
  69. break;
  70. }
  71. }
  72. system("pause");
  73. return 0;
  74. }
Add Comment
Please, Sign In to add comment