Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Book
  7. {
  8. private:
  9.     string title;
  10.     string authorName;
  11.     string authorFamily;
  12.     string date;
  13. public:
  14.     Book();
  15.     Book(string _title,
  16.          string _authorName,
  17.          string _authorFamily,
  18.          string _date);
  19.     friend ostream& operator<< (ostream &obj, const Book &obj2);
  20.     string getTitle();
  21.     string getAuthorName();
  22.     string getAuthorFamily();
  23.     string getDate();
  24. };
  25.  
  26. class Library:public Book
  27. {
  28. private:
  29.     const int numberOfBooks;
  30.     Book* books;
  31. public:
  32.     Library(int _number);
  33.     void fillBooks();
  34.     void find(string date);
  35. };
  36.  
  37. Book::Book():
  38.     title(),
  39.     authorName(),
  40.     authorFamily(),
  41.     date()
  42. {}
  43. Book::Book(string _title,
  44.            string _authorName,
  45.            string _authorFamily,
  46.            string _date):
  47.            title(_title),
  48.            authorName(_authorName),
  49.            authorFamily(_authorFamily),
  50.            date(_date)
  51. {}
  52. string Book::getTitle(){return title;}
  53. string Book::getAuthorName(){return authorName;}
  54. string Book::getAuthorFamily(){return authorFamily;}
  55. string Book::getDate(){return date;}
  56.  
  57. ostream& operator<< (ostream &obj, Book &obj2)
  58. {
  59.     cout << "Title: ";
  60.     obj << obj2.getTitle() <<"\n";
  61.     cout << "Author Name: ";
  62.     obj << obj2.getAuthorName()<<" "<<obj2.getAuthorFamily()<<"\n";
  63.     cout << "Date:";
  64.     obj << obj2.getDate()<<"\n";
  65.     return obj;
  66. }
  67.  
  68. Library::Library(int _number):
  69.                  numberOfBooks(_number)
  70. {      
  71.     books = new Book[numberOfBooks];
  72.     fillBooks();
  73. }
  74.  
  75. void Library::fillBooks()
  76. {
  77.     if(numberOfBooks!=0){
  78.         string title;
  79.         string authorName;
  80.         string authorFamily;
  81.         string date;
  82.         for(int i = 0;i < numberOfBooks;i++)
  83.         {
  84.             cout << "Input Book Title: ";
  85.             cin >> title;
  86.             cout << "Input Author Name: ";
  87.             cin >> authorName;
  88.             cout << "Input Author Family: ";
  89.             cin >> authorFamily;
  90.             cout << "Input Date taken: ";
  91.             cin >> date;
  92.             books[i] = Book(&title[0], &authorName[0], &authorFamily[0], &date[0]);
  93.         }
  94.     }else
  95.     {
  96.         cout << "No books";
  97.     }
  98. }
  99.  
  100. void Library::find(string date)
  101. {
  102.     for(int i = 0;i < numberOfBooks;i++){
  103.         if(date == books[i].getDate()){
  104.             cout << books[i];
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement