Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Edition {
- public:
- void name(const string& value) { name_ = value; }
- void author(const string& value) { author_ = value; }
- string name()const { return name_; }
- string author()const { return author_; }
- virtual void show()const = 0;
- private:
- string name_;
- string author_;
- };
- class Book : virtual public Edition {
- public:
- void publishing(unsigned short value) { publishing_ = value; }
- void publishing_house(const string& value) { publishing_house_ = value; }
- unsigned short publishing()const { return publishing_; }
- string publishing_house()const { return publishing_house_; }
- void show()const override {
- cout
- << "Автор: " << author() << '\n'
- << "Название книги: " << name() << '\n'
- << "Издательство: " << publishing_house() << '\n'
- << "Год издания: " << publishing() << '\n';
- }
- private:
- unsigned short publishing_;
- string publishing_house_;
- };
- class Article : virtual public Edition {
- public:
- void number(int value) { number_ = value; }
- void year(int value) { year_ = value; }
- void title(const string& value) { title_ = value; }
- int number()const { return number_; }
- int year()const { return year_; }
- string title()const { return title_; }
- void show()const override {
- cout
- << "Автор: " << author() << '\n'
- << "Название статьи: " << name() << '\n'
- << "Название журнала: " << title() << '\n'
- << "Номер журнала: " << number() << '\n'
- << "Год публикации: " << year() << '\n';
- }
- private:
- int number_;
- int year_;
- string title_;
- };
- class Catalog {
- public:
- explicit Catalog(const size_t limit) : limit_(limit) {}
- bool add(Edition* ptr) {
- if (box_.size() < limit_) box_.push_back(ptr);
- return box_.size() < limit_;
- }
- vector<Edition*> find_author(const string& author)const {
- vector<Edition*> box;
- for (auto item : box_) if (item->author() == author) box.push_back(item);
- return box;
- }
- void show()const {
- for (auto item : box_) {
- item->show();
- cout.put('\n');
- }
- }
- private:
- size_t limit_;
- vector<Edition*> box_;
- };
- Book input_book() {
- Book book;
- cout << "Имя автора книги: ";
- string author;
- getline(cin, author);
- book.author(author);
- cout << "Название книги: ";
- string name;
- getline(cin, name);
- book.name(name);
- cout << "Издательство: ";
- string publishing_house;
- getline(cin, publishing_house);
- book.publishing_house(publishing_house);
- cout << "Год издания: ";
- unsigned short publishing;
- cin >> publishing;
- book.publishing(publishing);
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- system("cls");
- return book;
- }
- Article input_article() {
- Article article;
- cout << "Имя автора статьи: ";
- string author;
- getline(cin, author);
- article.author(author);
- cout << "Название статьи: ";
- string name;
- getline(cin, name);
- article.name(name);
- cout << "Название журнала: ";
- string title;
- getline(cin, title);
- article.title(title);
- cout << "Номер журнала: ";
- int number;
- cin >> number;
- article.number(number);
- cout << "Год издания: ";
- int year;
- cin >> year;
- article.number(year);
- article.year(year);
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- system("cls");
- return article;
- }
- int main() {
- system("chcp 1251 > nul");
- const auto limit = 5U;
- Catalog catalog(limit);
- auto b1 = input_book();
- catalog.add(&b1);
- auto a1 = input_article();
- catalog.add(&a1);
- auto a2 = input_article();
- catalog.add(&a2);
- auto b2 = input_book();
- catalog.add(&b2);
- auto a3 = input_article();
- catalog.add(&a3);
- catalog.show();
- cout << "Введите имя автора для поиска: ";
- string author;
- getline(cin, author);
- cout.put('\n');
- auto box = catalog.find_author(author);
- if (box.size() > 0) {
- for (auto item : box) {
- item->show();
- cout.put('\n');
- }
- }
- else cout << "Не найден!\n";
- system("pause > nul");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement