-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathE5.h
63 lines (51 loc) · 1.51 KB
/
E5.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef E5_H
#define E5_H
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::istream;
using std::ostream;
#include <string>
using std::string;
class Book{
friend istream& operator>>(istream&, Book&);
friend ostream& operator<<(ostream&, const Book&);
friend bool operator==(const Book&, const Book&);
friend bool operator!=(const Book&, const Book&);
public:
Book()=default;
Book(unsigned no, string name, string author, string pubdate):no_(no), name_(name), author_(author),pubdate_(pubdate) {}
Book(istream& is){ is >> *this; }
private:
unsigned no_;
string name_;
string author_;
string pubdate_;
};
istream& operator>>(istream&, Book&);
ostream& operator<<(ostream& os, const Book& book);
bool operator==(const Book& lhs, const Book& rhs);
bool operator!=(const Book& lhs, const Book& rhs);
istream& operator>>(istream& is, Book& book){
is >> book.no_ >> book.name_ >> book.author_ >> book.pubdate_;
if(!is){
book = Book();
}
return is;
}
ostream& operator<<(ostream& os, const Book& book){
os << book.no_ << " name is : " << book.name_;
return os;
}
bool operator==(const Book& lhs, const Book& rhs){
if(lhs.no_ == rhs.no_ && lhs.name_ == rhs.name_){
return true;
} else {
return false;
}
}
bool operator!=(const Book& lhs, const Book& rhs){
return !(lhs == rhs);
}
#endif