Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BookInTheLibrary.h"
- // перегрузка оператора присваивания
- BookInTheLibrary& BookInTheLibrary::operator= (const BookInTheLibrary& ob) // оператор присваивания
- {
- author_ = ob.author_;
- title_ = ob.title_;
- publishingYear_ = ob.publishingYear_;
- discipline_ = ob.discipline_;
- numberOfCopies_ = ob.numberOfCopies_;
- return *this;
- }
- // перегрузка бинарных операторов
- BookInTheLibrary BookInTheLibrary::operator+ (unsigned int value)
- {
- return BookInTheLibrary(numberOfCopies_ + value);
- }
- BookInTheLibrary BookInTheLibrary::operator- (unsigned int value)
- {
- return BookInTheLibrary(numberOfCopies_ - value);
- }
- // перегрузка операторов отношения
- bool BookInTheLibrary::operator== (const BookInTheLibrary& ob) const
- {
- return (publishingYear_ == ob.publishingYear_);
- }
- bool BookInTheLibrary::operator> (const BookInTheLibrary& ob) const
- {
- return (publishingYear_ > ob.publishingYear_);
- }
- bool BookInTheLibrary::operator< (const BookInTheLibrary& ob) const
- {
- return (publishingYear_ < ob.publishingYear_);
- }
- bool BookInTheLibrary::operator>= (const BookInTheLibrary& ob) const
- {
- return (publishingYear_ >= ob.publishingYear_);
- }
- bool BookInTheLibrary::operator<= (const BookInTheLibrary& ob) const
- {
- return (publishingYear_ <= ob.publishingYear_);
- }
- // перегрузка операторов инкремента/декремента
- BookInTheLibrary& BookInTheLibrary::operator++()
- {
- ++numberOfCopies_;
- return *this;
- }
- BookInTheLibrary& BookInTheLibrary::operator--()
- {
- --numberOfCopies_;
- return *this;
- }
- // перегрузка операторов ввода/вывода через дружественные функции
- ostream& operator<< (ostream& out, const BookInTheLibrary& ob)
- {
- out << "Author - " << ob.author_ << ", title - " << ob.title_ << ", publishing year - "
- << ob.publishingYear_ << ", recommended discipline - " << ob.discipline_
- << ", number of copies - " << ob.numberOfCopies_;
- return out;
- }
- istream& operator>> (istream& in, BookInTheLibrary& ob)
- {
- in >> ob.author_;
- in >> ob.title_;
- in >> ob.publishingYear_;
- in >> ob.discipline_;
- in >> ob.numberOfCopies_;
- return in;
- }
- // конструкторы/деструктор
- BookInTheLibrary::BookInTheLibrary() // конструктор без параметров
- : author_("N/A"), title_("N/A"), publishingYear_(0), discipline_("N/A"), numberOfCopies_(0) {}
- BookInTheLibrary::BookInTheLibrary(string author, string title, unsigned int publishingYear, string discipline, unsigned int numberOfCopies) // конструктор копирования
- : author_(author), title_(title), publishingYear_(publishingYear), discipline_(discipline), numberOfCopies_(numberOfCopies) {}
- BookInTheLibrary::BookInTheLibrary(unsigned int numberOfCopies) // конструктор копирования кол-ва копий
- : numberOfCopies_(numberOfCopies) {}
- BookInTheLibrary::BookInTheLibrary(const BookInTheLibrary& ob) // конструктор копирования
- : author_(ob.author_), title_(ob.title_), publishingYear_(ob.publishingYear_),
- discipline_(ob.discipline_), numberOfCopies_(ob.numberOfCopies_) {}
- BookInTheLibrary::~BookInTheLibrary() {}
Add Comment
Please, Sign In to add comment