Advertisement
35657

Untitled

Mar 9th, 2024
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.46 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. struct film {
  9.     char name[40];
  10.     char producer[40];
  11.     char genre[40];
  12.     int rating;
  13. };
  14.  
  15. struct video_store {
  16.     film store[100];
  17.     int films_number = 0;
  18. };
  19.  
  20. void show_all_movies(const video_store& some_store) {
  21.     for (int i = 0; i < some_store.films_number; ++i) {
  22.         cout << '\"' << some_store.store[i].name << "\", продюсер: " << some_store.store[i].producer << ", " << some_store.store[i].genre << ", рейтинг " << some_store.store[i].rating << endl;
  23.     }
  24.     cout << endl;
  25. }
  26.  
  27. void add_movie(video_store& some_store, const char* name, const char* producer, const char* genre, const int rating) {
  28.     if (some_store.films_number == 100) {
  29.         cout << "Фильм не может быть добавлен" << endl;
  30.         return;
  31.     }
  32.     strcpy(some_store.store[some_store.films_number].name, name);
  33.     strcpy(some_store.store[some_store.films_number].producer, producer);
  34.     strcpy(some_store.store[some_store.films_number].genre, genre);
  35.     some_store.store[some_store.films_number].rating = rating;
  36.     some_store.films_number++;
  37. }
  38.  
  39. void del_movie(video_store& some_store, const char* name) {
  40.     for (int i = 0; i < some_store.films_number; i++) {
  41.         if (!strcmp(some_store.store[i].name, name)) {
  42.             for (int j = i; j < some_store.films_number - 1; j++) {
  43.                 some_store.store[j] = some_store.store[j + 1];
  44.             }
  45.             some_store.films_number--;
  46.         }
  47.     }
  48. }
  49.  
  50. void find_movie_name(const video_store& some_store, const char* name) {
  51.     for (int i = 0; i < some_store.films_number; i++) {
  52.         if (!strcmp(some_store.store[i].name, name)) {
  53.             cout << '\"' << some_store.store[i].name << "\", продюсер: " << some_store.store[i].producer << ", " << some_store.store[i].genre << ", рейтинг " << some_store.store[i].rating << endl;
  54.         }
  55.     }
  56.     cout << endl;
  57. }
  58.  
  59. void find_movie_producer(video_store& some_store, const char* producer) {
  60.     for (int i = 0; i < some_store.films_number; i++) {
  61.         if (!strcmp(some_store.store[i].producer, producer)) {
  62.             cout << '\"' << some_store.store[i].name << "\", продюсер: " << some_store.store[i].producer << ", " << some_store.store[i].genre << ", рейтинг " << some_store.store[i].rating << endl;
  63.         }
  64.     }
  65.     cout << endl;
  66. }
  67.  
  68. void find_movie_genre(video_store& some_store, const char* genre) {
  69.     for (int i = 0; i < some_store.films_number; i++) {
  70.         if (!strcmp(some_store.store[i].genre, genre)) {
  71.             cout << '\"' << some_store.store[i].name << "\", продюсер: " << some_store.store[i].producer << ", " << some_store.store[i].genre << ", рейтинг " << some_store.store[i].rating << endl;
  72.         }
  73.     }
  74.     cout << endl;
  75. }
  76.  
  77. void find_movie_most_popular(video_store& some_store, const char genre[]) {
  78.     int index = -1;
  79.     int rating = 0;
  80.     for (int i = 0; i < some_store.films_number; i++) {
  81.         if (!strcmp(some_store.store[i].genre, genre)) {
  82.             if (some_store.store[i].rating > rating) {
  83.                 index = i;
  84.                 rating = some_store.store[i].rating;
  85.             }
  86.         }
  87.     }
  88.     if (index != -1) {
  89.         cout << '\"' << some_store.store[index].name << "\", продюсер: " << some_store.store[index].producer << ", " << some_store.store[index].genre << ", рейтинг " << some_store.store[index].rating << endl;
  90.     }
  91.     cout << endl;
  92. }
  93.  
  94.  
  95. int main() {
  96.  
  97.     setlocale(LC_ALL, "ru");
  98.  
  99.     video_store my_store;
  100.  
  101.     add_movie(my_store, "Пираты Карибского моря", "Гор Вербински", "фантастика", 5);
  102.     add_movie(my_store, "Гарри Поттер", "Крис Коламбус", "фантастика", 4);
  103.     add_movie(my_store, "Бриллиантовая рука", "Леонид Гайдай", "комедия", 5);
  104.     add_movie(my_store, "Иван Васильевич меняет профессию", "Леонид Гайдай", "комедия", 4);
  105.     add_movie(my_store, "Шерлок Холмс", "Гай Ричи", "детектив", 5);
  106.     add_movie(my_store, "Карты, деньги, два ствола", "Гай Ричи", "комедия", 5);
  107.  
  108.     show_all_movies(my_store);
  109.  
  110.     del_movie(my_store, "Пираты Карибского моря");
  111.  
  112.     show_all_movies(my_store);
  113.  
  114.     add_movie(my_store, "Пираты Карибского моря", "Гор Вербински", "фантастика", 5);
  115.  
  116.     find_movie_name(my_store, "Бриллиантовая рука");
  117.  
  118.     find_movie_producer(my_store, "Гай Ричи");
  119.  
  120.     find_movie_genre(my_store, "фантастика");
  121.  
  122.     find_movie_most_popular(my_store, "фантастика");
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement