#include <iostream>
#include <string>
#include <vector>

class Book {
    int id;
    std::string name;
    std::string writer;
    std::string year;

   public:
    Book() {}

    Book(unsigned id, std::string name, std::string writer, std::string year) {
        this->id = id;
        this->name = name;
        this->writer = writer;
        this->year = year;
    }

    std::string& get_name() {
        return name;
    }
    std::string& get_writer() {
        return writer;
    }
    std::string& get_year() {
        return year;
    }

    void setname(std::string name) {
        this->name = name;
    }
    void setwriter(std::string writer) {
        this->name = name;
    }
    void setyear(std::string year) {
        this->name = name;
    }
};

class Reader {
    std::string name;
    unsigned number;

   public:
    Reader() {}

    Reader(std::string name, unsigned number) {
        this->name = name;
        this->number = number;
    }

    std::string& getName() {
        return name;
    }

    unsigned getNumber() {
        return number;
    }

    void setName(std::string name) {
        this->name = name;
    }

    void setNumber(unsigned number) {
        this->number = number;
    }
};

class Library {
   public:
    Reader* readers;
    size_t amount_readers;
    Book* books;
    size_t amount_books;

    Library() {
        readers = new Reader[0];
        amount_readers = 0;
        books = new Book[0];
        amount_books = 0;
    }

    void addReader(Reader reader) {
        Reader* new_readers = new Reader[amount_readers + 1];
        for (size_t i = 0; i < amount_readers; i++) {
            new_readers[i] = readers[i];
        }
        new_readers[amount_readers] = reader;
        delete[] readers;
        readers = new_readers;
        amount_readers++;
    }

    void addBook(Book book) {
        Book* new_books = new Book[amount_books + 1];
        for (size_t i = 0; i < amount_books; i++) {
            new_books[i] = books[i];
        }
        new_books[amount_books] = book;
        delete[] books;
        books = new_books;
        amount_books++;
    }

    Book deleteBook(size_t n) {
        Book* new_books = new Book[amount_books - 1];

        for (size_t i = 0; i < n; i++) {
            new_books[i] = books[i];
        }

        for (size_t j = n + 1; j < amount_books; j++) {
            new_books[j - 1] = books[j];
        }
        Book deleted = books[n];
        delete[] books;
        books = new_books;
        amount_books -= 1;
        return deleted;
    }

    Book takeBook(size_t n) {
        Book taken = this->deleteBook(n);
        std::cout << "Book" << taken.get_name() << "is taken\n";
        return taken;
    }

    void returnBook(Book book) {
        std::cout << "Book" << book.get_name() << "is returned\n";
        this->addBook(book);
    }
};

int main() {
    Book WarAndPeace(0, "WarAndPeace", "Tolstoy", "1867");
    Book EugeneOnegin(1, "EugeneOnegin", "Pushkin", "1832");
    Book HeroOfOurTime(2, "HeroOfOurTime", "Lemontov", "1840");
    Book PortraitOfDorianGray(3, "PortraitOfDorianGray", "Wilde", "1890");

    Library library;
    library.addBook(WarAndPeace);
    library.addBook(EugeneOnegin);
    library.addBook(HeroOfOurTime);
    library.addBook(PortraitOfDorianGray);

    Reader petya("Petya", 0);
    Reader vasya("Vasya", 1);
    library.addReader(petya);
    library.addReader(vasya);

    Book book1 = library.takeBook(0);
    Book book2 = library.takeBook(0);

    library.returnBook(book1);
    library.returnBook(book2);

    library.takeBook(3);
}