-
Notifications
You must be signed in to change notification settings - Fork 0
/
return.cpp
79 lines (71 loc) · 2.87 KB
/
return.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
#include "return.h"
#include "librarySystem.h"
//----------------------------------------------------------------------------
//constructor
//sets the transaction type character to R
Return::Return() {
transactionType = 'R';
}
//----------------------------------------------------------------------------
//setData
//reads patronID, bookType, bookPresentation, creates a book of the correct
//type using the book factory and then calls partialSetData. Prints error
//for id not in system, book not in system, incorrect book format, incorrect
//book type,
bool Return::setData(istream& istr, LibrarySystem& system) {
BookFactory factory;
string emptyLine;
istr >> patronID;
istr >> bookType;
istr >> bookPresentation;
tempPatron = system.findPatron(patronID); //get patron from system
if (tempPatron == nullptr) { //check if patron wasnt in system
cout << "ERROR: Patron ID " << patronID << " not in system." << endl;
getline(istr, emptyLine); //reading in rest of line
return false;
}
if (bookPresentation != 'H') { //check if book presentation is correct
cout << "ERROR: '" << bookPresentation
<< "' is not a valid book format." << endl;
getline(istr, emptyLine); //reading in rest of line
return false;
}
else { //book presentation is correct
targetBook = factory.createIt(bookType); //get book from factory
if (targetBook != nullptr) { //book type is correct
targetBook->partialSetData(istr); //set data for target
book = system.findBook(targetBook); //get book from system
if (book == nullptr) { //book was not in system
cout << "ERROR: " << tempPatron->getPatronName() <<
" tried returning '" << targetBook->getTitle() <<
"' - not found in catalog." << endl;
delete targetBook;
targetBook = nullptr;
return false;
}
}
else { //book type is incorrect
cout << "ERROR: '" << bookType << "' is not a valid book type."
<< endl;
getline(istr, emptyLine); //reading in rest of line
return false;
}
}
return true;
}
//----------------------------------------------------------------------------
//printTransaction
//displays the transaction as transaction type and the partial book data
void Return::printTransaction() const {
if (book != nullptr) {
cout.setf(ios::left, ios::adjustfield);
cout << setw(12) << " Return";
book->printPartial();
}
}
//----------------------------------------------------------------------------
//processTran
//checks book in for book in this transaction
void Return::processTran(LibrarySystem& system) const {
book->checkin();
}