35657

Untitled

Feb 3rd, 2024
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct book {
  6.     char title[40];
  7.     char author[40];
  8.     char publisher[40];
  9.     char genre[40];
  10. };
  11.  
  12.  
  13. void print_book(const book* arr, const int size) {
  14.     for (int i = 0; i < size; i++) {
  15.         cout << arr[i].title << ", автор - " << arr[i].author << ", издательство " << arr[i].publisher << ", жанр - " << arr[i].genre << endl;
  16.     }
  17. }
  18.  
  19. void find_book_title(const book* arr, const int size, const char* title) {
  20.     for (int i = 0; i < size; i++) {
  21.         if (!strcmp(title, arr[i].title)) {
  22.             cout << arr[i].title << ", автор - " << arr[i].author << ", издательство " << arr[i].publisher << ", жанр - " << arr[i].genre << endl;
  23.         }
  24.     }
  25. }
  26.  
  27. void find_book_author(const book* arr, const int size, const char* author) {
  28.     for (int i = 0; i < size; i++) {
  29.         if (!strcmp(author, arr[i].author)) {
  30.             cout << arr[i].title << ", автор - " << arr[i].author << ", издательство " << arr[i].publisher << ", жанр - " << arr[i].genre << endl;
  31.         }
  32.     }
  33. }
  34.  
  35. int main() {
  36.  
  37.     setlocale(LC_ALL, "ru");
  38.  
  39.     const int size = 5;
  40.  
  41.     book library[size];
  42.  
  43.     library[0] = { "Мастер и Маргарита", "Михаил Булгаков", "Лабиринт", "роман" };
  44.     library[1] = { "Собачье сердце", "Михаил Булгаков", "Питер", "повесть" };
  45.     library[2] = { "Палата № 6", "Антон Чехов", "Питер", "повесть" };
  46.     library[3] = { "Война и мир", "Лев Толстой", "АСТ", "роман" };
  47.     library[4] = { "Обломов", "Иван Гончаров", "Лабиринт", "роман" };
  48.  
  49.     print_book(library, size);
  50.  
  51.     cout << endl << endl;
  52.  
  53.     find_book_title(library, size, "Палата № 6");
  54.  
  55.     cout << endl << endl;
  56.  
  57.     find_book_author(library, size, "Михаил Булгаков");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment