Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- class Book {
- private:
- std::string author;
- std::string title;
- std::string publisher;
- int year;
- int quantity;
- int pages;
- public:
- explicit Book(const std::string& author, const std::string& title, const std::string& publisher,
- int year, int quantity, int pages)
- : author(author), title(title), publisher(publisher), year(year), quantity(quantity), pages(pages) {}
- const std::string& getAuthor() const {
- return author;
- }
- const std::string& getTitle() const {
- return title;
- }
- const std::string& getPublisher() const {
- return publisher;
- }
- int getYear() const {
- return year;
- }
- int getQuantity() const {
- return quantity;
- }
- int getPages() const {
- return pages;
- }
- void display() const {
- std::cout << "Author: " << author << std::endl;
- std::cout << "Title: " << title << std::endl;
- std::cout << "Publisher: " << publisher << std::endl;
- std::cout << "Year: " << year << std::endl;
- std::cout << "Quantity: " << quantity << std::endl;
- std::cout << "Pages: " << pages << std::endl;
- std::cout << std::endl;
- }
- };
- int main() {
- std::vector<Book> books;
- // Добавляем книги в массив
- books.emplace_back("Author 1", "Title 1", "Publisher 1", 2020, 5, 200);
- books.emplace_back("Author 2", "Title 2", "Publisher 2", 2021, 3, 150);
- books.emplace_back("Author 1", "Title 3", "Publisher 3", 2022, 2, 300);
- books.emplace_back("Author 3", "Title 4", "Publisher 1", 2022, 4, 250);
- books.emplace_back("Author 2", "Title 5", "Publisher 2", 2023, 1, 180);
- // Список книг заданного автора
- std::cout << "Список книг заданного автора:" << std::endl;
- std::string searchAuthor = "Author 1";
- for (const auto& book : books) {
- if (book.getAuthor() == searchAuthor) {
- book.display();
- }
- }
- // Список книг, выпущенных заданным издательством
- std::cout << "Список книг, выпущенных заданным издательством:" << std::endl;
- std::string searchPublisher = "Publisher 2";
- for (const auto& book : books) {
- if (book.getPublisher() == searchPublisher) {
- book.display();
- }
- }
- // Список книг, выпущенных после заданного года
- std::cout << "Список книг, выпущенных после заданного года:" << std::endl;
- int searchYear = 2021;
- for (const auto& book : books) {
- if (book.getYear() > searchYear) {
- book.display();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement