Advertisement
35657

Untitled

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