Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Book
- {
- private:
- string title;
- string authorName;
- string authorFamily;
- string date;
- public:
- Book();
- Book(string _title,
- string _authorName,
- string _authorFamily,
- string _date);
- friend ostream& operator<< (ostream &obj, const Book &obj2);
- string getTitle();
- string getAuthorName();
- string getAuthorFamily();
- string getDate();
- };
- class Library:public Book
- {
- private:
- const int numberOfBooks;
- Book* books;
- public:
- Library(int _number);
- void fillBooks();
- void find(string date);
- };
- Book::Book():
- title(),
- authorName(),
- authorFamily(),
- date()
- {}
- Book::Book(string _title,
- string _authorName,
- string _authorFamily,
- string _date):
- title(_title),
- authorName(_authorName),
- authorFamily(_authorFamily),
- date(_date)
- {}
- string Book::getTitle(){return title;}
- string Book::getAuthorName(){return authorName;}
- string Book::getAuthorFamily(){return authorFamily;}
- string Book::getDate(){return date;}
- ostream& operator<< (ostream &obj, Book &obj2)
- {
- cout << "Title: ";
- obj << obj2.getTitle() <<"\n";
- cout << "Author Name: ";
- obj << obj2.getAuthorName()<<" "<<obj2.getAuthorFamily()<<"\n";
- cout << "Date:";
- obj << obj2.getDate()<<"\n";
- return obj;
- }
- Library::Library(int _number):
- numberOfBooks(_number)
- {
- books = new Book[numberOfBooks];
- fillBooks();
- }
- void Library::fillBooks()
- {
- if(numberOfBooks!=0){
- string title;
- string authorName;
- string authorFamily;
- string date;
- for(int i = 0;i < numberOfBooks;i++)
- {
- cout << "Input Book Title: ";
- cin >> title;
- cout << "Input Author Name: ";
- cin >> authorName;
- cout << "Input Author Family: ";
- cin >> authorFamily;
- cout << "Input Date taken: ";
- cin >> date;
- books[i] = Book(&title[0], &authorName[0], &authorFamily[0], &date[0]);
- }
- }else
- {
- cout << "No books";
- }
- }
- void Library::find(string date)
- {
- for(int i = 0;i < numberOfBooks;i++){
- if(date == books[i].getDate()){
- cout << books[i];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement