-
Notifications
You must be signed in to change notification settings - Fork 0
/
periodical.cpp
103 lines (92 loc) · 3.44 KB
/
periodical.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "periodical.h"
//----------------------------------------------------------------------------
//print
//formats and displays the periodical stock, title, month and year.
void Periodical::print() const {
cout.setf(ios::left, ios::adjustfield);
cout << setw(AVAILABILITY_OUTPUT_WIDTH) << instock
<< setw(TITLE_OUTPUT_WIDTH) << title.substr(0, TITLE_MAX_WIDTH)
<< setw(MONTH_OUTPUT_WIDTH) << month
<< year << endl;
}
//----------------------------------------------------------------------------
//setData
//reads from istream the title, month, year, and sets them accordingly. Also
//sets the type to P and the stock to 1 which could be set from file
void Periodical::setData(istream& istr) {
bookType = 'P';
instock = 1;
istr.get();
getline(istr, title, ',');
istr >> month;
istr >> year;
}
//----------------------------------------------------------------------------
//partialSetData
//reads book presentation author and title from istr and
//sets data accordingly (called by transaction class)
void Periodical::partialSetData(istream& istr) {
bookType = 'P';
istr >> year;
istr >> month;
istr.get();
getline(istr, title, ',');
}
//----------------------------------------------------------------------------
//operator==
//returns true only if the year, month, and title are the same for both books
bool Periodical::operator==(const Book& other) const {
const Periodical& temp = static_cast<const Periodical&>(other);//cast
if (year != temp.year || month != temp.month) { //check months
return false;
}
else if (title != temp.title) { //check title
return false;
}
else {
return true;
}
}
//----------------------------------------------------------------------------
//operator<
//sorts by year, then month and then title. If year is less returns true.
//If year is same and month is less return true. If year and month are same
//and title is alphabetically before other title then return true. Otherwise
//return false
bool Periodical::operator<(const Book& other) const {
const Periodical& temp = static_cast<const Periodical&>(other);//cast
if (year < temp.year) { //check year
return true;
}
else if (year == temp.year && month < temp.month) { //check month
return true;
}
else if (year == temp.year && month == temp.month
&& title < temp.title) { //check title
return true;
}
else {
return false;
}
}
//----------------------------------------------------------------------------
//printHeader
//prints the header for displaying in catagory
void Periodical::printHeader() const {
cout.setf(ios::left, ios::adjustfield);
cout << "PERIODICALS BOOKS " << endl;
cout << setw(AVAILABILITY_OUTPUT_WIDTH) << "AVAIL"
<< setw(TITLE_OUTPUT_WIDTH) << "TITLE"
<< setw(MONTH_OUTPUT_WIDTH) << "MONTH"
<< "YEAR" << endl;
}
//----------------------------------------------------------------------------
//printPartial
//prints the partial data that is set in the transaction class.
//only prints the title, month, and year using setw
void Periodical::printPartial() const {
cout.setf(ios::left, ios::adjustfield);
cout << setw(PTITLE_OUTPUT_WIDTH) << title.substr(0, PTITLE_MAX_WIDTH)
<< setw(MONTH_OUTPUT_WIDTH) << month
<< year << endl;
}