LAB9_ANTONUS
unknown
c_cpp
3 years ago
2.6 kB
9
Indexable
#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);}
int 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;
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()
{
//сам заполни, а то мне лень
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;
}
}Editor is loading...