Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- #include<string.h>
- #include<locale.h>
- #define INPUT_FILMS 1
- #define OUTPUT_FILMS 2
- #define FIND_ACTORS 3
- #define EXIT 4
- #define COMEDY 1
- #define HORROR 2
- #define THRILLER 3
- #define MELODRAMA 4
- //меню
- int menu() {
- printf("Меню:\n");
- printf("1. Ввести инофрмацию о фильмах.\n");
- printf("2. Вывести информацию о фильмах.\n");
- printf("3. Найти фильм с наибольшим числом актеров.\n");
- printf("4. Выход.\n");
- printf("Выберите дальнейшее действие: ");
- return 0;
- }
- // выделение памяти под массивы
- int allocate_mamory(int n, char*** names, int** year, int**types, char****actors, int**how_actors) {
- *names = new char*[n];
- for (int i = 0; i < n; i++)
- (*names)[i] = new char[100];
- *year = new int[n];
- *types = new int[n];
- *how_actors = new int[n];
- *actors = new char**[n];
- return 0;
- }
- //освобождение памяти
- int free_memory(int n, char*** names, int** year, int**types, char****actors, int**how_actors) {
- delete[] * year;
- *year = NULL;
- delete[] * types;
- *types = NULL;
- delete[] * how_actors;
- *how_actors = NULL;
- for (int i = 0; i < n; i++) {
- delete[](*names)[i];
- //из под имен актеров
- for (int j = 0; j < (*how_actors)[i]; j++) {
- delete[](*actors)[i][j];
- }
- delete[](*actors)[i];
- delete[](*actors);
- }
- delete[] * names;
- *names = NULL;
- *actors = NULL;
- return 0;
- }
- //вводим массив фильмов
- int imput_films(int* n, char*** names, int** year, int** types, char****actors, int**how_actors) {
- //проверка , введен ли массив:
- if (*n != 0)
- return -1;
- printf("\nВведите количество фильмов\n");
- scanf_s("%i", n);
- //выделим память
- allocate_mamory(*n, names, year, types, actors, how_actors);
- //вводим массив фильмов:
- char films_type_2 [100];
- for (int i = 0; i < *n; i++) {
- printf("\nФильм №: %i \n", (i+1));
- printf("\nВведите название фильма\n");
- scanf_s ("%s ",(*names)[i]);
- printf("\nВведите тип фильма: комедия, ужасы, боевик или мелодрама\n");
- scanf_s("%s ", films_type_2);
- if (strcmp(films_type_2, "комедия"))
- (*types)[i] = COMEDY;
- if (strcmp(films_type_2, "ужасы"))
- (*types)[i] = HORROR;
- if (strcmp(films_type_2, "боевик"))
- (*types)[i] = THRILLER;
- if (strcmp(films_type_2, "мелодрама"))
- (*types)[i] = MELODRAMA;
- printf("\nвведите дату выпуска фильма\n");
- scanf_s("%i", &(*year)[i]);
- printf("\nвведите количество актеров в фильме № %i\n", i);
- scanf_s("%i", &(*how_actors)[i]);
- //выделим память на массив имен актеров
- (*actors)[i] = new char*[((*how_actors)[i])];
- printf("\nвведите имена актеров в фильме № %i\n", i);
- int j;
- for (j = 0; j < (*how_actors)[i]; j++) {
- (*actors)[i][j] = new char[100];
- printf("Актер № %i", j);
- scanf_s("%s", (*actors)[i][j]);
- }
- }
- return 0;
- }
- //функция вывода массива фильмов
- int output_films(int n, char** names, int* year, int*types, char***actors, int*how_actors){
- //проверка
- if (n == 0)
- return -1;
- //выводим массив
- for(int i=0; i<n;i++){
- printf("\n фильм № %i:\n", i);
- printf("Название: %s\n", names[i]);
- if (types[i] == COMEDY);
- printf("Тип: комедия \n");
- if( types[i] == HORROR);
- printf("Тип: ужасы\n");
- if (types[i] == THRILLER);
- printf("Тип: боевик\n");
- if (types[i] == MELODRAMA);
- printf("Тип: мелодрама\n");
- printf("Год: %i\n", year[i]);
- int j = 0;
- printf("Актеры: ");
- for (j = 0; j < how_actors[i]; j++)
- printf("%lf ", actors[i][j]);
- printf("\n");
- }
- return 0;
- }
- //функция поиска фильма, в котором снялось наибольшее количество актеров
- int find_actors(int n, int* how_actors) {
- //проверка
- if (n == 0)
- return -1;
- int i;
- int max = 0;
- for (i = 0; i < n; i++) {
- if (how_actors[i] > max) {
- max = how_actors[i];
- }
- }
- return max;
- }
- int main() {
- setlocale(LC_ALL, "rus");
- // названия фильмов
- char** names = NULL;
- // дата выпуска
- int* year = NULL;
- // типы фильмов
- int* types = NULL;
- //имена актеров
- char*** actors = NULL;
- // количество актеров в каждом фильме
- int* how_actors = NULL;
- int n = 0;
- int menu1 = 0;
- while (1) {
- menu();
- scanf_s("%i", &menu1);
- if (menu1 == INPUT_FILMS) {
- if (imput_films(&n, &names, &year, &types, &actors, &how_actors) == -1)
- printf("массив уже введен");
- }
- if (menu1 == OUTPUT_FILMS) {
- if (output_films(n, names, year, types, actors, how_actors) == -1)
- printf("Массив ещё не введён\n");
- }
- if (menu1 == FIND_ACTORS) {
- int a = find_actors(n, how_actors);
- if (a == -1)
- printf("Массив ещё не введён\n");
- else
- printf("Фильм с наибольшим числом актеров № %i\n", a);
- }
- if (menu1 == EXIT) {
- free_memory(n, &names, &year, &types, &actors, &how_actors);
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement