-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.cpp
More file actions
75 lines (62 loc) · 1.97 KB
/
Copy pathhistory.cpp
File metadata and controls
75 lines (62 loc) · 1.97 KB
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
// Handles the operation of retrieving the history of a Patron within the
// library system. Returns and outputs their rental history of books from the
// library.
//
// Assumptions:
// -- will only be called on a valid item in the library
//
// Implementation:
// -- no destructor implementation for dynamic memory in create() method -
// -- memory deallocation to be handled by Patron class where commands are
// -- are stored in itemHistory list
//---------------------------------------------------------------------------
#include "history.h"
#include "Library.h"
#include "patroncontainer.h"
#include <iostream>
//---------------------------------------------------------------------------
// constructor
History::History() {
commType_ = 'H';
item_ = nullptr;
patron_ = nullptr;
libraryPtr_ = nullptr;
}
//---------------------------------------------------------------------------
// Destructor
History::~History() {}
//---------------------------------------------------------------------------
// build Command
// data format: PatronID
bool History::buildCommand(istream &inStream, Library *&library) {
bool success = false;
inStream.get(); // clear space
int ID;
// read patron ID
inStream >> ID;
Patron *patron;
// check library for patron
if (library->getPatron(ID, patron)) {
patron_ = patron;
success = true;
}
else {
cout << endl
<< "ERROR: User ID \"" << ID << "\" is an invalid patron ID"
<< endl;
}
return success;
}
//---------------------------------------------------------------------------
// execute
bool History::execute() {
patron_->displayPatron();
patron_->printHistory();
return true;
}
//---------------------------------------------------------------------------
// display
void History::display() {}
//---------------------------------------------------------------------------
// create
Command *History::create() { return new History(); }