Я заруинил бл

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
3.2 kB
3
Indexable
Never
#include <iostream>
#include <cstring>

using namespace std;

const int StrLen = 250;

class Book
{
    private:
    char Title[20];
    char AuthorName[15];
    char AuthorSurname[15];
    char Publisher[15];
    int ReleaseYear;
   
    public:
    char *GetTitle() { return Title; }
    char *GetAuthorName() { return AuthorName; }
    char *GetAuthorSurname() { return AuthorSurname; }
    char *GetPublisher() { return Publisher; }
    int GetReleaseYear(){ return ReleaseYear; }

    
    void SetTitle(char *title) { strcpy(Title, title);}
    void SetAuthorName(char *authorName) { strcpy(AuthorName, authorName);}
    void SetAuthorSurname(char *authorSurname) { strcpy(AuthorSurname, authorSurname);}
    void SetPublisher(char *publisher) { strcpy(Publisher, publisher);}
    void SetReleaseYear(int year) { ReleaseYear = year; }
};

istream &operator>>(istream &stream, Book &obj)
{
    char str[StrLen];
    
    cout << "\nEnter title: ";
    cin.getline(str, StrLen);
    obj.SetTitle(str);
    
    cout << "\nEnter author's name: ";
    cin.getline(str, StrLen);
    obj.SetAuthorName(str);
    
    cout << "\nEnter author's surname: ";
    cin.getline(str, StrLen);
    obj.SetAuthorSurname(str);
    
    cout << "\nEnter publisher: ";
    cin.getline(str, StrLen);
    obj.SetPublisher(str);
    
    int year;
    cout << "\nEnter release year: ";
    cin >> year;
    cin.ignore();
    obj.SetReleaseYear(year);
    
    return stream;
}
ostream &operator<<(ostream &stream, Book &obj)
{
    stream 
    << " " << obj.GetTitle()
    << " " << obj.GetAuthorName()
    << " " << obj.GetAuthorSurname()
    << " " << obj.GetPublisher()
    << " " << obj.GetReleaseYear();
    
    return stream;
}

void InitArray(Book*, int);
void DisplayArray(Book*, int);
void DisplayChoise(Book*, int, char*, int, int);

int main()
{
    int length;
    int lowerYear, higherYear;
    char publisher[20];
    
    
    cout << "\nEnter films count: ";
    cin >> length;
    
    Book *books = new Book[length];
    InitArray(books, length);
    
    cout << "\nThe list of films:\n";
    DisplayArray(books, length);
    
    
    cout << "\nEnter production country: ";
    cin.ignore();
    cin.getline(publisher, StrLen);
    
    cout << "\nEnter lower release date: ";
    cin >> lowerYear;
    
    cout << "\nEnter higher release date: ";
    cin >> higherYear;
    
    DisplayChoise(books, length, publisher, lowerYear, higherYear);
    
    delete []books;
    return 0;
}

void InitArray(Book *books, int len)
{
    cin.ignore();
    for(int i = 0; i < len; i++)
    {
        cout << flush << "\nEnter the information about " << i + 1 << "-th " << "book";
        cin >> books[i];
    }
}
void DisplayArray(Book *books, int len)
{
    for(int i = 0; i < len; i++)
    {
        cout << books[i] << endl;
    }
}
void DisplayChoise(Book *books, int len, char *publisher, int lowerYear, int higherYear)
{
    for(int i = 0; i < len; i++)
    {
        Book book = books[i];
        if(strcmp(book.GetPublisher(), publisher) == 0 && book.GetReleaseYear() < higherYear && book.GetReleaseYear() > lowerYear)
            cout << book << endl;
    }
}