Advertisement
Guest User

library

a guest
Jan 20th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. class Book
  11. {
  12. private:
  13. string b_name;
  14. int b_sheets;
  15. public:
  16. Book()
  17. {
  18. b_name = "";
  19. b_sheets = 0;
  20. }
  21. Book(string a, int b)
  22. {
  23. b_name = a;
  24. b_sheets = b;
  25. }
  26. string getbname()
  27. {
  28. return b_name;
  29. }
  30. int getsheets()
  31. {
  32. return b_sheets;
  33. }
  34. bool operator<(Book &a)
  35. {
  36. return b_name < a.b_name;
  37. }
  38. bool operator==(Book &a)
  39. {
  40. return b_name == a.b_name;
  41. }
  42. inline Book operator+(Book &a)
  43. {
  44. this->b_sheets += a.b_sheets;
  45. return *this;
  46. }
  47. friend istream& operator>>(istream& in, Book &a)
  48. {
  49. in >> a.b_name >> a.b_sheets;
  50. return in;
  51. }
  52. friend ostream& operator<<(ostream& out, Book &a)
  53. {
  54. out << a.b_name << " " << a.b_sheets << endl;
  55. return out;
  56. }
  57. };
  58.  
  59. class Library
  60. {
  61. private:
  62. string l_name;
  63. vector<Book>l_v;
  64. public:
  65. Library(string f)
  66. {
  67. ifstream ifile(f, ios::in);
  68. if (ifile.is_open())
  69. {
  70. ifile >> l_name;
  71. copy(l_v.begin(), !ifile.eof());
  72. ifile.close();
  73. }
  74. else
  75. {
  76. cout << "File couldn't be opened!";
  77. exit(1);
  78. }
  79. }
  80. Library()
  81. {
  82. l_v.resize(NULL);
  83. }
  84. string getlname()
  85. {
  86. return l_name;
  87. }
  88. void setl_name(string a)
  89. {
  90. l_name = a;
  91. }
  92. vector<Book> get(vector<Book>v)
  93. {
  94. vector<Book>temp;
  95. unique_copy(v.begin(), v.end(), temp.begin());
  96. return temp;
  97. }
  98. int sum(vector<Book>v)
  99. {
  100. int broi(0);
  101. for (auto x : v)
  102. {
  103. x++;
  104. broi++;
  105. }
  106. return broi;
  107. }
  108. friend istream& operator>>(istream& in, Library &a)
  109. {
  110. in >> a.l_name >> a.l_v;
  111. return in;
  112. }
  113. friend ostream& operator<<(ostream& out, Library &a)
  114. {
  115. out << a.l_name << endl;
  116. copy(a.l_v.begin(), a.l_v.end());
  117. return out;
  118. }
  119. };
  120.  
  121. int main()
  122. {
  123. Library a("neshtosi");
  124. cout << a;
  125. cout << a.get(a.l_v);
  126. cout << a.sum(a.l_v);
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement