Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Book {
  8. private:
  9.     string name;
  10.     vector<string> authors;
  11.     string dateTaken;
  12. public:
  13.     Book(string name, string author, string date) {
  14.         this->name = name;
  15.         this->authors.push_back(author);
  16.         this->dateTaken = date;
  17.     }
  18.  
  19.     Book(string name, vector<string> authors, string date) {
  20.         this->name = name;
  21.         this->dateTaken = date;
  22.        
  23.         this->authors.insert(this->authors.end(), authors.begin(), authors.end());
  24.     }
  25.  
  26.     string getName() const { return this->name; }
  27.     string getDateTaken() const { return this->dateTaken; }
  28.     vector<string> getAuthors() const { return this->authors; }
  29.  
  30.     friend ostream& operator<<(ostream& os, const Book& book);
  31. };
  32.  
  33. ostream &operator<<(ostream &os, const Book& book) {
  34.     os << "Book name: " << book.getName() << "\n";
  35.  
  36.     return os;
  37. }
  38.  
  39. class Library {
  40. private:
  41.     int bookCount;
  42.     vector<Book> books;
  43. public:
  44.     void addBook(const Book& book) {
  45.         bookCount++;
  46.         this->books.push_back(book);
  47.     }
  48.  
  49.     void addBooks(vector<Book> booksVector) {
  50.         bookCount += booksVector.size();
  51.         this->books.insert(this->books.end(), booksVector.begin(), booksVector.end());
  52.     }
  53.  
  54.     vector<Book> filterByDateTaken(const string& date) {
  55.         vector<Book> takenBooks;
  56.         for (auto & book : this->books) {
  57.             if (book.getDateTaken() == date) {
  58.                 takenBooks.push_back(book);
  59.             }
  60.         }
  61.  
  62.         return takenBooks;
  63.     }
  64. };
  65.  
  66. int main() {
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement