-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatrons.cpp
241 lines (155 loc) · 4.84 KB
/
patrons.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "patrons.h"
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <time.h>
using namespace std;
void Patrons::AddPatron() {
string name;
Patron currPatron;
srand (time(0));
cout << "Enter Patron Name: ";
getline(cin,name);
currPatron.SetId(rand() % 10000 + 10000);
currPatron.SetName(name);
currPatron.SetFineBal(0.0);
currPatron.SetBooksOut(0);
PatronList.push_back(currPatron);
}
void Patrons::EditPatron(int i) {
int newBooksOut = PatronList.at(i).GetBooksOut() + 1;
PatronList.at(i).SetBooksOut(newBooksOut);
}
void Patrons::EditPatron2(int id) {
int newBooksOut = PatronList.at(id).GetBooksOut() - 1;
PatronList.at(id).SetBooksOut(newBooksOut);
}
void Patrons::EditPatron3(int id, int sec) {
float newFineBal = PatronList.at(id).GetFineBal() + (sec / 86400)*(.25);
PatronList.at(id).SetFineBal(newFineBal);
}
void Patrons::EditPatron4(int id, int bookId, LibrayItems &items) {
float bookCost = items.GetItemCost2(bookId);
float newBal = PatronList.at(id).GetFineBal() + bookCost;
PatronList.at(id).SetFineBal(newBal);
}
void Patrons::DeletePatron(int id) {
int i = FindPatron2(id);
if(PatronList.at(i).GetBooksOut() == 0 && PatronList.at(i).GetFineBal() == 0.0 && PatronIdCheck(id) == true) {
if( i == 0) {
PatronList.erase(PatronList.begin());
}
else if (i != 0 && i !=PatronList.size()) {
PatronList.erase(PatronList.begin() + i);
}
else if( i == PatronList.size()) {
PatronList.pop_back();
}
}
else {
if(PatronList.at(i).GetBooksOut() != 0 && PatronIdCheck(id) == true) {
cout << "Patron Has Existing Check Outs. Please Check in all of Patron's Books" << endl;
}
else if(PatronList.at(i).GetFineBal() != 0 && PatronIdCheck(id) == true) {
cout << "Patron Has Existing An Fine Balance. Please Have Patron Pay Fines." << endl;
}
else if (PatronIdCheck(id) != true) {
cout << "Patron Id Not Found" << endl;
}
}
}
int Patrons::FindPatron(string name) {
for(int i = 0; i < PatronList.size(); i++) {
if(PatronList.at(i).GetName() == name) {
return i;
}
}
}
int Patrons::FindPatron2(int id) {
for(int i = 0; i < PatronList.size(); i++) {
if(PatronList.at(i).GetId() == id) {
return i;
}
}
}
void Patrons::PrintPatron(int id) {
if(PatronIdCheck(id) == true) {
int i = FindPatron2(id);
cout << "Name: " << PatronList.at(i).GetName() << ", ";
cout << "Patron Id: " << PatronList.at(i).GetId() << ", ";
cout << "Fine Balance: " << PatronList.at(i).GetFineBal() << ", ";
cout << "Books Out: " << PatronList.at(i).GetBooksOut() << " " << endl << endl;
}
}
void Patrons::PrintPatrons() {
cout << "ALL PATRONS: " << endl << endl;
for(int i = 0; i < PatronList.size(); i++) {
cout << "Name: " << PatronList.at(i).GetName() << ", ";
cout << "Patron Id: " << PatronList.at(i).GetId() << ", ";
cout << "Fine Balance: " << PatronList.at(i).GetFineBal() << ", ";
cout << "Books Out: " << PatronList.at(i).GetBooksOut() << " " << endl << endl;
}
}
void Patrons::PayFines(int id) {
if(PatronIdCheck(id) == true) {
int i = FindPatron2(id);
PatronList.at(i).SetFineBal(0.0);
PrintPatron(id);
}
else {
if (PatronIdCheck(id) != true) {
cout << "Patron Id Not Found" << endl;
}
}
}
int Patrons::GetPatronId2(string name) {
return PatronList.at(FindPatron(name)).GetId();
}
int Patrons::GetPatronId3(int id) {
return PatronList.at(FindPatron2(id)).GetId();
}
int Patrons::GetBooksOut2(int id) {
return PatronList.at(FindPatron2(id)).GetBooksOut();
}
bool Patrons::PatronIdCheck(int id) {
if(PatronList.at(FindPatron2(id)).GetId() == id) {
return true;
}
}
void Patrons::LoadPatrons() {
Patron currPatron;
string name;
int id;
float bal;
int booksout;
int count = 0;
ifstream infile ("patrons.dat");
infile >> count;
infile.ignore();
for(int i = 0; i < count; i++) {
getline(infile,name);
infile >> id;
infile.ignore();
infile >> bal;
infile.ignore();
infile >> booksout;
infile.ignore();
currPatron.SetId(id);
currPatron.SetName(name);
currPatron.SetFineBal(bal);
currPatron.SetBooksOut(booksout);
PatronList.push_back(currPatron);
}
infile.close();
}
void Patrons::StorePatrons() {
ofstream outfile("patrons.dat");
outfile << PatronList.size() << endl;
for(int i = 0; i < PatronList.size(); i++) {
outfile << PatronList.at(i).GetName() << endl;
outfile << PatronList.at(i).GetId() << endl;
outfile << PatronList.at(i).GetFineBal() << endl;
outfile << PatronList.at(i).GetBooksOut() << endl;
}
outfile.close();
}