Neveles

Untitled

Dec 1st, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include "BookInTheLibrary.h"
  2.  
  3. // перегрузка оператора присваивания
  4. BookInTheLibrary& BookInTheLibrary::operator= (const BookInTheLibrary& ob) // оператор присваивания
  5. {
  6.     author_ = ob.author_;
  7.     title_ = ob.title_;
  8.     publishingYear_ = ob.publishingYear_;
  9.     discipline_ = ob.discipline_;
  10.     numberOfCopies_ = ob.numberOfCopies_;
  11.     return *this;
  12. }
  13.  
  14. // перегрузка бинарных операторов
  15. BookInTheLibrary BookInTheLibrary::operator+ (unsigned int value)
  16. {
  17.     return BookInTheLibrary(numberOfCopies_ + value);
  18. }
  19. BookInTheLibrary BookInTheLibrary::operator- (unsigned int value)
  20. {
  21.     return BookInTheLibrary(numberOfCopies_ - value);
  22. }
  23.  
  24. // перегрузка операторов отношения
  25. bool BookInTheLibrary::operator== (const BookInTheLibrary& ob) const
  26. {
  27.     return (publishingYear_ == ob.publishingYear_);
  28. }
  29. bool BookInTheLibrary::operator> (const BookInTheLibrary& ob) const
  30. {
  31.     return (publishingYear_ > ob.publishingYear_);
  32. }
  33. bool BookInTheLibrary::operator< (const BookInTheLibrary& ob) const
  34. {
  35.     return (publishingYear_ < ob.publishingYear_);
  36. }
  37. bool BookInTheLibrary::operator>= (const BookInTheLibrary& ob) const
  38. {
  39.     return (publishingYear_ >= ob.publishingYear_);
  40. }
  41. bool BookInTheLibrary::operator<= (const BookInTheLibrary& ob) const
  42. {
  43.     return (publishingYear_ <= ob.publishingYear_);
  44. }
  45.  
  46. // перегрузка операторов инкремента/декремента
  47. BookInTheLibrary& BookInTheLibrary::operator++()
  48. {
  49.     ++numberOfCopies_;
  50.     return *this;
  51. }
  52. BookInTheLibrary& BookInTheLibrary::operator--()
  53. {
  54.     --numberOfCopies_;
  55.     return *this;
  56. }
  57.  
  58. // перегрузка операторов ввода/вывода через дружественные функции
  59. ostream& operator<< (ostream& out, const BookInTheLibrary& ob)
  60. {
  61.     out << "Author - " << ob.author_ << ", title - " << ob.title_ << ", publishing year - "
  62.         << ob.publishingYear_ << ", recommended discipline - " << ob.discipline_
  63.         << ", number of copies - " << ob.numberOfCopies_;
  64.     return out;
  65. }
  66. istream& operator>> (istream& in, BookInTheLibrary& ob)
  67. {
  68.     in >> ob.author_;
  69.     in >> ob.title_;
  70.     in >> ob.publishingYear_;
  71.     in >> ob.discipline_;
  72.     in >> ob.numberOfCopies_;
  73.     return in;
  74. }
  75.  
  76. // конструкторы/деструктор
  77. BookInTheLibrary::BookInTheLibrary() // конструктор без параметров
  78.     : author_("N/A"), title_("N/A"), publishingYear_(0), discipline_("N/A"), numberOfCopies_(0) {}
  79. BookInTheLibrary::BookInTheLibrary(string author, string title, unsigned int publishingYear, string discipline, unsigned int numberOfCopies) // конструктор копирования
  80.     : author_(author), title_(title), publishingYear_(publishingYear), discipline_(discipline), numberOfCopies_(numberOfCopies) {}
  81. BookInTheLibrary::BookInTheLibrary(unsigned int numberOfCopies) // конструктор копирования кол-ва копий
  82.     : numberOfCopies_(numberOfCopies) {}
  83. BookInTheLibrary::BookInTheLibrary(const BookInTheLibrary& ob) // конструктор копирования
  84.     : author_(ob.author_), title_(ob.title_), publishingYear_(ob.publishingYear_),
  85.     discipline_(ob.discipline_), numberOfCopies_(ob.numberOfCopies_) {}
  86.  
  87. BookInTheLibrary::~BookInTheLibrary() {}
Add Comment
Please, Sign In to add comment