C/C++

Помогите с задачей пожалуйста

Сформироватьмассив, каждыйэлементкоторогоимеетследующую структуру
книга = автор: string; название: string; год издание: integer; издательство: string; количество страниц: integer;
определить:
есть ли в библиотеке книги данного автора;
найти книгу с наибольшим количеством страниц
найти названия книг данного автора, изданных с указанного года.
Nazim Gadaridze
Nazim Gadaridze
180
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int integer(istream& inp, const char* msg) {
cout << msg;
int value;
inp >> value;
inp.ignore(inp.rdbuf()->in_avail());
return value;
}
string line(istream& inp, const char* msg) {
cout << msg;
string value;
getline(inp, value);
return value;
}
struct Book {
int side;
int year;
string author;
string title;
string publisher;
Book() : side(0), year(1455) {}
friend bool operator>(const Book& a, const Book& b) {
return a.year > b.year;
}
friend istream& operator>>(istream& inp, Book& book) {
book.author = line(inp, "Автор: ");
book.title = line(inp, "Название: ");
book.year = integer(inp, "Год издания: ");
book.publisher = line(inp, "Издательство: ");
book.side = integer(inp, "Количество страниц: ");
return inp;
}
};
class Library {
public:
void add(const Book& book) {
books.push_back(book);
}
bool includes_author(const string& author)const {
for (const auto& book : books) {
if (book.author == author) {
return true;
}
}
return false;
}
Book sides_max()const {
auto max = books.front();
for (const auto& book : books) {
if (book > max) {
max = book;
}
}
return max;
}
vector<Book> query_ay(const string& author, const int year)const {
vector<Book> answer;
for (const auto& book : books) {
if (book.author == author && book.year >= year) {
answer.push_back(book);
}
}
return answer;
}
private:
vector<Book> books;
};
int main() {
system("chcp 1251 > nul");
Library lib;
Book book;
for (auto i = 0; i < 2; ++i) {
cin >> book;
lib.add(book);
}
system("cls");
auto author = line(cin, "Введите автора: ");
puts(lib.includes_author(author) ? " - есть книги" : " - нет книг");

auto max = lib.sides_max();
puts("Книга с наибольшим количеством страниц:");
cout
<< max.author << R"( ")"
<< max.title << R"(", )"
<< max.side << " стр. \n";

author = line(cin, "Введите автора: ");
auto year = integer(cin, "Введите год издания: ");
puts("Список книг автора начиная с указанного гда:");
auto list = lib.query_ay(author, year);
for (const auto& item : list) {
cout << item.title << ", " << item.year << '\n';
}
system("pause > nul");
}
Нурак Jna
Нурак Jna
73 028
Лучший ответ