LAB8

Лабораторная работа №8.
mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.7 kB
3
Indexable
Never
#include <iostream>

using namespace std;

struct Film
{
    char Title[40];
    char DirectorName[15];
    char DirectorSurname[15];
    char Country[20];
    int ReleaseDate;
    int Income;
    int Profit; 
};

Film InitFilm();
void DisplayFilm(Film);
void InitArray(Film*, int);
void DisplayArray(Film*, int);
void DisplayChoise(Film*, int, char*, char*, int);

const int STR_LEN = 250;

int main()
{
    int length;
    char directorName[15]; 
    char directorSurname[15];
    int releaseDate;
    
    cout << "\nEnter films count: ";
    cin >> length;
    
    Film *films = new Film[length];
    InitArray(films, length);
    
    cout << "\nThe list of films:\n";
    DisplayArray(films, length);
    
    cout << "\nEnter director's name: ";
    cin.getline(directorName, 15);
    
    cout << "\nEnter director's surname: ";
    cin.getline(directorSurname, 15);
    
    cout << "\nEnter release date: ";
    cin >> releaseDate;
    
    DisplayChoise(films, length, directorName, directorSurname, releaseDate);
    
    delete []films;
    
    return 0;
}
Film InitFilm()
{
    Film film;
    
    cout << "\nEnter film title: ";
    cin.ignore();
    cin.getline(film.Title, STR_LEN);
    
    cout << "\nEnter director name: ";
    cin.getline(film.DirectorName, STR_LEN);
    
    cout << "\nEnter director surname: ";
    cin.getline(film.DirectorSurname, STR_LEN);
    
    cout << "\n Enter production country: ";
    cin.getline(film.Country, STR_LEN);
    
    cout << "\nEnter release date: ";
    cin >> film.ReleaseDate;
    
    cout << "\nEnter film income: ";
    cin >> film.Income;
    
    cout << "\nEnter film profit: ";
    cin >> film.Profit;
    
    return film;
}
void DisplayFilm(Film film)
{
    cout << film.Title 
    << " " << film.ReleaseDate 
    << " " << film.DirectorName
    << " " << film.DirectorSurname
    << " " << film.Country
    << " " << film.Income 
    << " " << film.Profit
    ;
}
void InitArray(Film *films, int len)
{
    for(int i = 0; i < len; i++)
    {
        cout << "Enter the info about " << i + 1 << "-th " << " film" << endl;
        films[i] = InitFilm();
    }
}
void DisplayArray(Film *films, int len)
{
    for(int i = 0; i < len; i++)
    {
        cout << endl;
        DisplayFilm(films[i]);
    }
}
void DisplayChoise(Film *films, int len, char *directorName, char *directorSurname, int releaseDate)
{
    for(int i = 0; i < len; i++)
    {
        Film film = films[i];
        if(film.DirectorName == directorName 
            || film.DirectorSurname == directorSurname
            || film.ReleaseDate == releaseDate)
        {
            cout << endl;
            DisplayFilm(film);
        }
    }
}