35657

Untitled

Feb 6th, 2024 (edited)
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  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(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. }
  57.  
  58. int main() {
  59.  
  60.     setlocale(LC_ALL, "ru");
  61.  
  62.     video_store my_store;
  63.  
  64.     add_movie(my_store, "Пираты Карибского моря", "Гор Вербински", "фантастика", 4);
  65.     add_movie(my_store, "Гарри Поттер", "Крис Коламбус", "фантастика", 4);
  66.     add_movie(my_store, "Бриллиантовая рука", "Леонид Гайдай", "комедия", 5);
  67.     add_movie(my_store, "Иван Васильевич меняет профессию", "Леонид Гайдай", "комедия", 5);
  68.     add_movie(my_store, "Шерлок Холмс", "Гай Ричи", "детектив", 5);
  69.     add_movie(my_store, "Карты, деньги, два ствола", "Гай Ричи", "комедия", 5);
  70.  
  71.     show_all_movies(my_store);
  72.  
  73.     del_movie(my_store, "Пираты Карибского моря");
  74.  
  75.     show_all_movies(my_store);
  76.  
  77.     add_movie(my_store, "Пираты Карибского моря", "Гор Вербински", "фантастика", 4);
  78.  
  79.     show_all_movies(my_store);
  80.  
  81.     find_movie_name(my_store, "Шерлок Холмс");
  82. }
Advertisement
Add Comment
Please, Sign In to add comment