forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex14_15.cpp
50 lines (41 loc) · 983 Bytes
/
ex14_15.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "ex14_15.h"
std::istream& operator>>(std::istream& in, Book& book)
{
in >> book.no_ >> book.name_ >> book.author_ >> book.pubdate_ >>
book.number_;
if (!in) book = Book();
return in;
}
std::ostream& operator<<(std::ostream& out, const Book& book)
{
out << book.no_ << " " << book.name_ << " " << book.author_ << " "
<< book.pubdate_ << " " << book.number_ << std::endl;
return out;
}
bool operator==(const Book& lhs, const Book& rhs)
{
return lhs.no_ == rhs.no_;
}
bool operator!=(const Book& lhs, const Book& rhs)
{
return !(lhs == rhs);
}
bool operator<(const Book& lhs, const Book& rhs)
{
return lhs.no_ < rhs.no_;
}
bool operator>(const Book& lhs, const Book& rhs)
{
return rhs < lhs;
}
Book& Book::operator+=(const Book& rhs)
{
if (rhs == *this) this->number_ += rhs.number_;
return *this;
}
Book operator+(const Book& lhs, const Book& rhs)
{
Book book = lhs;
book += rhs;
return book;
}