35657

Untitled

May 7th, 2023
1,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.58 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  3.  
  4.  
  5. #include <iostream>
  6. #include <clocale>
  7. #include <string.h>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. struct film {
  13.     char name[100];
  14.     char producer[100];
  15.     char genre[20];
  16.     int rating;
  17. };
  18.  
  19. class video_store {
  20.  
  21. public:
  22.  
  23.     video_store() {
  24.         store = new film* [100];
  25.         films_number = 0;
  26.         max_films_number = 100;
  27.     };
  28.  
  29.     video_store(int max_number) {
  30.         store = new film* [max_number];
  31.         films_number = 0;
  32.         max_films_number = max_number;
  33.     };
  34.  
  35.     video_store(film arr[], int arr_size) {
  36.         store = new film * [100];
  37.         for (int i = 0; i < arr_size; i++) {
  38.             AddMovie(arr[i].name, arr[i].producer, arr[i].genre, arr[i].rating);
  39.         }
  40.         films_number = arr_size;
  41.         max_films_number = 100;
  42.     };
  43.  
  44.     void ShowAllMovies() {
  45.         cout << " По вашему запросу найдено: " << endl;
  46.         if (films_number == 0) {
  47.             cout << "Нет фильмов";
  48.         }
  49.         for (int i = 0; i < films_number; i++) {
  50.             cout << '\"' << store[i]->name << "\", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
  51.         }
  52.         cout << endl;
  53.     };
  54.  
  55.     void AddMovie(const char name[], const char producer[], const char genre[], const int rating) {
  56.         if (films_number == max_films_number) {
  57.             cout << "Фильм не может быть добавлен" << endl;
  58.             return;
  59.         }
  60.         store[films_number] = new film{};
  61.         strcpy(store[films_number]->name, name);
  62.         strcpy(store[films_number]->producer, producer);
  63.         strcpy(store[films_number]->genre, genre);
  64.         store[films_number]->rating = rating;
  65.         films_number++;
  66.     };
  67.  
  68.     void DelMovie(const char name[]) {
  69.         for (int i = 0; i < films_number; i++) {
  70.             if (!strcmp(store[i]->name, name)) {
  71.                 delete store[i];
  72.                 for (int j = i; j < films_number - 1; j++) {
  73.                     store[j] = store[j + 1];
  74.                 }
  75.                 store[films_number - 1] = nullptr;
  76.                 films_number--;
  77.             }
  78.         }
  79.     };
  80.  
  81.     void FindMovieName(const char name[]) {
  82.         cout << " По вашему запросу найдено: " << endl;
  83.         for (int i = 0; i < films_number; i++) {
  84.             if (!strcmp(store[i]->name, name)) {
  85.                 cout << '\"' << store[i]->name << "\", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
  86.             }
  87.         }
  88.         cout << endl;
  89.     };
  90.     void FindMovieProducer(const char producer[]) {
  91.         cout << " По вашему запросу найдено: " << endl;
  92.         for (int i = 0; i < films_number; i++) {
  93.             if (!strcmp(store[i]->producer, producer)) {
  94.                 cout << '\"' << store[i]->name << "\", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
  95.             }
  96.         }
  97.         cout << endl;
  98.     };
  99.     void FindMovieGenre(const char genre[]) {
  100.         cout << " По вашему запросу найдено: " << endl;
  101.         for (int i = 0; i < films_number; i++) {
  102.             if (!strcmp(store[i]->genre, genre)) {
  103.                 cout << '\"' << store[i]->name << "\", producer: " << store[i]->producer << ", genre: " << store[i]->genre << ", rating: " << store[i]->rating << endl;
  104.             }
  105.         }
  106.         cout << endl;
  107.     };
  108.     void FindMovieMostPopular(const char genre[]) {
  109.         cout << " По вашему запросу найдено: " << endl;
  110.         int index = -1;
  111.         int rating = 0;
  112.         for (int i = 0; i < films_number; i++) {
  113.             if (!strcmp(store[i]->genre, genre)) {
  114.                 if (store[i]->rating > rating) {
  115.                     index = i;
  116.                     rating = store[i]->rating;
  117.                 }
  118.             }
  119.         }
  120.         if (index != -1) {
  121.             cout << '\"' << store[index]->name << "\", producer: " << store[index]->producer << ", genre: " << store[index]->genre << ", rating: " << store[index]->rating << endl;
  122.         }
  123.         cout << endl;
  124.     };
  125.  
  126. private:
  127.     film** store;
  128.     int films_number;
  129.     int max_films_number;
  130. };
  131.  
  132.  
  133. int main() {
  134.  
  135.     setlocale(LC_ALL, "Russian");
  136.  
  137.     video_store my_store;
  138.  
  139.     my_store.AddMovie("Pirates of the Caribbean", "Gore Verbinski", "fantasy", 5);
  140.     my_store.AddMovie("Harry Potter", "Chris Columbus", "fantasy", 4);
  141.     my_store.AddMovie("Diamond Hand", "Leonid Gaidai", "comedy", 5);
  142.     my_store.AddMovie("Ivan Vasilyevich is changing his profession", "Leonid Gaidai", "comedy", 4);
  143.     my_store.AddMovie("Sherlock Holmes", "Guy Ritchie", "detective", 5);
  144.     my_store.AddMovie("Lock, Stock and Two Smoking Barrels", "Guy Ritchie", "comedy", 5);
  145.  
  146.     my_store.ShowAllMovies();
  147.  
  148.     my_store.DelMovie("Pirates of the Caribbean");
  149.  
  150.     my_store.ShowAllMovies();
  151.  
  152.     my_store.AddMovie("Pirates of the Caribbean", "Gore Verbinski", "fantasy", 5);
  153.  
  154.     my_store.FindMovieName("Diamond Hand");
  155.  
  156.     my_store.FindMovieProducer("Guy Ritchie");
  157.  
  158.     my_store.FindMovieGenre("fantasy");
  159.  
  160.     my_store.FindMovieMostPopular("fantasy");
  161. }
Advertisement
Add Comment
Please, Sign In to add comment