-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopy.cpp
190 lines (141 loc) · 4.23 KB
/
Copy.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//
// Copy.cpp
//
#include <iostream>
#include "Copy.h"
#include "Book.h"
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>
#include <algorithm>
using namespace std;
Copy::Copy() {
readername="noone";
ID=-1000;
borrowdate=-9;
expirationdate=-9;
reservationdate=-9;
}
Copy::Copy(Book tempbook) {
settitle(tempbook.gettitle());
setauthor(tempbook.getauthor());
setcategory(tempbook.getcategory());
setISBN(tempbook.getISBN());
setnumreservers(tempbook.getnumreservers());
setlistofreservers(tempbook.getlistofreservers());
readername="NoReader";
borrowdate=-1;
reservationdate=-1;
expirationdate=-1;
}
// overloaded operator to input copies from file
void Copy::operator>>(list<Copy>& mycopies) {
ifstream input;
int tempbookISBN, tempborrowdate, tempreservedate, tempexpdate, tempID;
string tempreadername;
Book tempbook, inputbook;
Copy tempcopy;
list<Book> mybooks;
inputbook>>mybooks;
input.open("copyfinal.dat");
if(input.fail()) {
cerr << "Error opening 'copyfinal.dat'." << endl;
}
while(input >> tempbookISBN) {
tempbook= whichbook(tempbookISBN, mybooks);
Copy tempcopy(tempbook);
input >> tempreadername >> tempborrowdate >> tempreservedate >> tempexpdate >> tempID;
tempcopy.setreadername(tempreadername);
tempcopy.setborrowdate(tempborrowdate);
tempcopy.setreservationdate(tempreservedate);
tempcopy.setexpirationdate(tempexpdate);
tempcopy.setID(tempID);
mycopies.push_back(tempcopy);
}
}
void Copy::setborrowdate(int tempborrowdate) {
borrowdate=tempborrowdate;
}
void Copy::setreadername(string tempreadername) {
readername=tempreadername;
}
void Copy::setexpirationdate(int tempexpirationdate) {
expirationdate=tempexpirationdate;
}
void Copy::setreservationdate(int tempreservationdate) {
reservationdate=tempreservationdate;
}
void Copy::setID(int tempid) {
ID=tempid;
}
void Copy::printCopy() {
printbook();
cout << "ID: " << setw(4) << setfill('0') << ID;
cout << "\nReader name: " << readername << "\nBorrow Date: " << borrowdate << "\nReservation Date: " << reservationdate << "\nExpiration Date: " << expirationdate << endl;
}
void Copy::printcopies(list<Copy>& mycopies) {
list<Copy>::iterator iterc;
for(iterc=mycopies.begin(); iterc!=mycopies.end();iterc++) {
Copy tempcopy=*iterc;
tempcopy.printCopy();
cout << endl;
}
}
// overloaded operator to output copies to file
void Copy::operator<<(list<Copy>& mycopies) {
ofstream output;
list<Copy>::iterator iterc;
output.open("copyfinal.dat");
if(output.fail()) {
cerr << "Error opening copyfinal.dat for output..." << endl;
}
for(iterc=mycopies.begin();iterc!=mycopies.end();iterc++) {
Copy tempcopy=*iterc;
output << tempcopy.getISBN() << "\n" << tempcopy.readername <<"\n" << tempcopy.borrowdate << "\n" << tempcopy.reservationdate << "\n" << tempcopy.expirationdate << "\n" << tempcopy.ID;
output << endl << endl;
}
output.close();
}
// overloaded operator to find copy based on ID
bool Copy::operator==(const Copy& rhs) {
//Copy tempcopyl;
//tempcopyl=rhs;
if(ID==rhs.ID) {
return true;
}
else {
return false;
}
}
// find copy based on ID
Copy Copy::whichcopy(int tempID, list<Copy>& mytempcopies) {
list<Copy>::iterator loopiter = mytempcopies.begin();
Copy tempcopy, defaultcopy;
int templistID;
for(loopiter=mytempcopies.begin();loopiter!=mytempcopies.end();loopiter++) {
tempcopy=*loopiter;
templistID=tempcopy.getID();
if(tempID==templistID) {
return tempcopy;
}
}
return defaultcopy;
}
int Copy::getID() {
return ID;
}
string Copy::getreadername() {
return readername;
}
int Copy::getexpirationdate() {
return expirationdate;
}
int Copy::getreservationdate() {
return reservationdate;
}
// updates copy info when it is returned
void Copy::copyreturned(int currentdate) {
reservationdate = currentdate;
readername = "NoReader";
}