-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatron.cpp
More file actions
69 lines (60 loc) · 2.02 KB
/
patron.cpp
File metadata and controls
69 lines (60 loc) · 2.02 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
#include "patron.h"
//----------------------------------------------------------------------------
//destructor
//clears transaction history and deletes list
Patron::~Patron() {
transQ.empty();
transQ.clear();
}
//----------------------------------------------------------------------------
//setPatron
//Takes istr and id as variables. Then it reads first and last name from a
//file and sets the data accordingly returns false and prints error message
//if invalid id
bool Patron::setPatron(istream& istr, const int id) {
ID = id;
istr >> lastName;
istr >> firstName;
if (ID < 1000 || ID > 9999) { //check for correct ID
cout << "ERROR: " << ID << " is an invalid ID" << endl;
return false;
}
else { //id is correct
return true;
}
}
//----------------------------------------------------------------------------
//displayPatron
//prints the patron data as ID LastName, FirstName
void Patron::displayPatron() const {
cout << ID << " "
<< lastName << ", "
<< firstName << ":" << endl;
}
//----------------------------------------------------------------------------
//addTransaction
//adds transaction to back of list
void Patron::addTransaction(Transaction* tran) {
transQ.push_back(tran);
}
//----------------------------------------------------------------------------
//displayTranHistory
//formats and displays transactions in the order they occurred for this
//patron
void Patron::displayTranHistory() {
if (transQ.empty()) {
return;
}
list<Transaction*>::iterator it;
//go through the transaction queue
for (it = transQ.begin(); it != transQ.end(); ++it) {
Transaction* tempTran = *it;
tempTran->printTransaction();
}
}
//----------------------------------------------------------------------------
//getPatronName
//returns the first and last name as a string
string Patron::getPatronName() const {
return(lastName + " " + firstName);
}