-
Notifications
You must be signed in to change notification settings - Fork 0
/
q5-h.cpp
68 lines (51 loc) · 1.8 KB
/
q5-h.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <string>
using namespace std;
class Book {
string ISBN_;
string title_;
string author_;
int copyright_;
bool checkedOut_;
public:
Book(const string& ISBN, const string& title, const string& author, int copyright)
: ISBN_(ISBN), author_(author), copyright_(copyright), title_(title), checkedOut_(false) {}
string getIsbn() const {return ISBN_; }
string getTitle() const {return title_; }
string getAuthor() const {return author_; }
int getCopyright() const {return copyright_;}
bool isCheckedOut() const {return checkedOut_; }
void checkIn() { checkedOut_ = false; }
void checkOut() {checkedOut_ = true;}
bool validIsbn(const string& ISBN) {
if (ISBN.length() != 5) {
return false;
}
for (int i = 0; i < 3; ++i) {
if (!isdigit(ISBN[i])) {
return false;
}
}
if (ISBN[3] != '-') {
return false;
}
if (!isalnum(ISBN[4])) {
return false;
}
return true;
}
};
int main() {
Book book("539-A", "Foundations of Computer Science - 4th Edition", "Behrouz Forouzan", 2005);
book.checkOut();
cout << "Book ISBN: " << book.getIsbn() <<endl;
cout << "Book Title: " << book.getTitle() << endl;
cout << "The Author: " << book.getAuthor() << endl;
cout << "Copyright: " << book.getCopyright() <<endl;
cout << "Checked out: " << book.isCheckedOut() <<endl;
book.checkIn();
cout << "Checked In: " << book.isCheckedOut() << endl;
cout << "Valid ISBN: " << book.validIsbn(book.getIsbn()) <<endl;
cout << "Invalid ISBN: " << book.validIsbn("1-3-5-7") <<endl;
return 0;
}