LAB_9
unknown
c_cpp
2 years ago
2.9 kB
7
Indexable
#include <iostream> #include <cstring> using namespace std; const int STR_LEN = 250; class Book { private: char Title[20]; char AuthorName[15]; char AuthorSurname[15]; char Publisher[15]; int ReleaseYear; /* int Expenses; int Income; int Profit; */ public: char *GetTitle() { return Title; } char *GetAuthorName() { return AuthorName; } char *GetAuthorSurname() { return AuthorSurname; } char *GetPublisher() { return Publisher; } int *GetReleaseYear(){ return ReleaseYear; } /* int *GetExpenses(){ return Expenses; } int *GetIncome(){ return Income; } int *GetProfit(){ return Profit; } */ void SetTitle(char *title) { strcpy(Title, title);} void SetTitle(char *authorName) { strcpy(AuthorName, authorName);} void SetTitle(char *authorSurname) { strcpy(AuthorSurname, authorSurname);} void SetTitle(char *publisher) { strcpy(Publisher, publisher);} int SetReleaseYear(int year) { ReleaseYear = year; } /* int SetExpenses(int expenses) { Expenses = expenses; } int SetIncome(int year) { Income = income; } int SetProfit(int year) { Profit = profit; } */ }; istream &operator>>(istream &stream, Book &obj) { char str[STR_LEN]; 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) && book.GetReleaseYear < higherYear && book.GetReleaseYear > lowerYear) cout << book << endl; } }
Editor is loading...