Endil

Untitled

Dec 9th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. class Book {
  2. private:
  3.     string isbn;
  4.     string author;
  5.     string title;
  6.     string year;
  7.     string publisher;
  8.     string page_count;
  9.     //friend auto BookList::search_by_author(string);
  10. public:
  11.     Book(string _isbn, string _author, string _title, string _year, string _publisher, string _page_count) {
  12.         isbn = _isbn;
  13.         author = _author;
  14.         title = _title;
  15.         year = _year;
  16.         publisher = _publisher;
  17.         page_count = _page_count;
  18.     }
  19.     auto serialize() {
  20.         auto s = isbn + "^^^" + author + "^^^" + title + "^^^" + year + "^^^" + publisher + "^^^" + page_count;
  21.         return s;
  22.     }
  23. };
  24.  
  25. class BookList {
  26. private:
  27.     vector<Book> list;
  28. public:
  29.     auto add(string isbn, string author, string title, string year, string publisher, string page_count) {
  30.         list.emplace_back(isbn, author, title, year, publisher, page_count);
  31.         return;
  32.     }
  33.     auto search_by_author(string author) {
  34.         vector<Book> matches;
  35.         for (auto book : list)
  36.             /*if (book.author == author)
  37.                 matches.push_back(book);*/
  38.         return matches;
  39.     }
  40.     auto serialize(vector<Book> entries) {
  41.         vector<string> serialized;
  42.         for (auto entry : entries)
  43.             serialized.push_back(entry.serialize());
  44.         return serialized;
  45.     }
  46. } books;
Advertisement
Add Comment
Please, Sign In to add comment