-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctionalities.cpp
More file actions
335 lines (321 loc) · 9.71 KB
/
Functionalities.cpp
File metadata and controls
335 lines (321 loc) · 9.71 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
// Include the necessary header files
#include "Functionalities.h"
// Function to save all data to files
void saveFiles(){
// Save all members, loans, librarians, and books
Librarian::saveMembers();
Loan::saveLoans();
Librarian::saveLibrarian();
Book::savelibrary();
}
// Function to load all data from files
void loadFiles(){
// Load all members, loans, librarians, and books
Librarian::loadMembers();
Loan::loadLoans();
Librarian::loadLibrarian();
Book::loadlibrary();
}
// Function to login a user
Custom_String_Class login(int id){
// Get all members and librarians
vector<Member>& member = Member::getMembers();
vector<Librarian>& librarian = Librarian::getLibrarians();
// Check if ID matches any member or librarian
for(auto it:member){
if(id==it.getID()){
return "member";
}
}
for(auto it:librarian){
if(id==it.getID()){
return "librarian";
}
}
return "not found";
}
// Function to load all data from files
void LoadFiles()
{
Book::loadlibrary();
Loan::loadLoans();
Librarian::loadMembers();
Librarian::loadLibrarian();
}
// Function to save all data to files
void SaveFiles()
{
Book::savelibrary();
Loan::saveLoans();
Librarian::saveMembers();
Librarian::saveLibrarian();
}
// Function to implement the choice of a member
void implementMemberChoice(Member& member, int memberOption){
cin.ignore();
switch (memberOption) {
case 1: {
// Option 1: Borrow a book
Book::displaylist();
cout << "\n Choose a book to borrow: ";
int choice;
cin >> choice;
vector<Book> bookList = Book::getBookList();
Book book = bookList[choice - 1];
member.requestBorrow(book);
break;
}
case 2: {
// Option 2: Return a book
member.displayloaned();
cout << "\n Choose a book to return: ";
int choice;
cin >> choice;
vector<Loan> loanedbooks = member.getCheckedOutBooks();
Book loanedbook = Book::findByISBN(loanedbooks[choice - 1].getBookID());
member.returnBook(loanedbook);
break;
}
case 3: {
// Option 3: Display loaned books
member.displayloaned();
break;
}
case 4: {
// Option 4: Display member details
member.display();
break;
}
case 5: {
// Option 5: Display all books
Book::displaylist();
break;
}
case 6: {
// Option 6: Find a book
displayMenuFindBook();
int findOptions;
cin >> findOptions;
implementFindBookChoice(findOptions);
break;
}
default: {
break;
}
}
}
// Function to implement the choice of the librarian
void implementLibrarianChoice(Librarian& librarian, int librarianOption){
cin.ignore();
switch (librarianOption) {
case 1:
// Option 1: Add a book
librarian.addBook();
break;
case 2: {
// Option 2: Remove a book
Book::displaylist();
int choice;
cout << "\n Enter you choice: ";
cin >> choice;
vector<Book> bookList = Book::getBookList();
Book book = bookList[choice - 1];
librarian.removeBook(book.getISBN());
break;
}
case 3:
// Option 3: Register a new member
librarian.registerNewMember();
break;
case 4: {
// Option 4: Remove a member
librarian.displayAllMembers();
int choice;
cout << "\n Enter you choice: ";
cin >> choice;
vector<Member> members= Member::getMembers();
Member member = members[choice-1];
librarian.removeMember(member.getID());
break;
}
case 5: {
// Option 5: Edit a book
Book::displaylist();
int choice;
cout << "\n Enter you choice: ";
cin >> choice;
Book& book = Book::getBookList()[choice - 1];
librarian.editBook(book);
break;
}
case 6: {
// Option 6: Approve a borrow request
librarian.displayRequests();
int choice;
cin >> choice;
vector<Loan>& requests = Librarian::getBorrowRequests();
Loan loan = requests[choice - 1];
librarian.approveBorrowRequest(loan);
break;
}
case 7: {
// Option 7: Return a book
cout << "Enter member ID: ";
int memberId;
cin >> memberId;
cin.ignore();
Member member = Librarian::findMemberByID(memberId);
cout << "Enter ISBN of book to return: ";
Custom_String_Class isbn;
cin >> isbn;
Book book = Book::findByISBN(isbn);
librarian.returnBook(member, book);
break;
}
case 8:
// Option 8: Display all members
librarian.displayAllMembers();
break;
case 9:
// Option 9: Display all books
Book::displaylist();
break;
case 10:
// Option 10: Display all requests
librarian.displayRequests();
break;
case 11:
// Option 11: Display all loans
Loan::displaylist();
break;
case 12: {
// Option 12: Find a book
displayMenuFindBook();
int findOptions;
cin >> findOptions;
implementFindBookChoice(findOptions);
break;
}
case 13: {
// Option 13: Find a member
displayMenuFindMember();
int findOptions;
cin >> findOptions;
implementFindMemberChoice(findOptions);
break;
}
case 14: {
// Option 14: Find a librarian
displayMenuFindlibrarian();
int findOptions;
cin >> findOptions;
implementFindLibrarianChoice(findOptions);
break;
}
default:
break;
}
}
// Function to implement the choice of finding a book
void implementFindBookChoice(int option){
switch (option) {
case 1: {
// Option 1: Find a book by ISBN
cout << "enter the ISBN of the book you want to find" << endl;
Custom_String_Class isbn;
cin.ignore();
cin >> isbn;
Book bk = Book::findByISBN(isbn);
if (!(bk.getTitle() == Book().getTitle()))
bk.displayBook();
break;
}
case 2: {
// Option 2: Find a book by title
cout << "enter the title of the book you want to find" << endl;
Custom_String_Class title;
cin.ignore();
cin >> title;
Book bk = Book::findByName(title);
if (!(bk.getTitle() == Book().getTitle()))
bk.displayBook();
break;
}
case 3: {
// Option 3: Find a book by author
cout << "enter the name of author of the book you want to find" << endl;
Custom_String_Class author;
cin.ignore();
cin >> author;
Book bk = Book::findByAuthor(author);
if (!(bk.getTitle() == Book().getTitle()))
bk.displayBook();
break;
}
default: {
break;
}
}
}
// Function to implement the choice of finding a member
void implementFindMemberChoice(int option){
switch (option) {
case 1: {
// Option 1: Find a member by name
cout << "enter the name of the member you want to find" << endl;
Custom_String_Class name;
cin.ignore();
cin >> name;
Member member = Librarian::findMemberByName(name);
cout<<"\n";
if (!(member.getName() == Member().getName()))
member.display();
break;
}
case 2: {
// Option 2: Find a member by ID
cout << "enter the ID of the member you want to find" << endl;
int id;
cin >> id;
Member member = Librarian::findMemberByID(id);
cout<<"\n";
if (!(member.getName() == Member().getName()))
member.display();
break;
}
default: {
break;
}
}
}
// Function to implement the choice of finding a librarian
void implementFindLibrarianChoice(int option){
switch (option) {
case 1: {
// Option 1: Find a librarian by name
cout << "enter the name of the librarian you want to find" << endl;
Custom_String_Class name;
cin.ignore();
cin >> name;
Librarian librarian = Librarian::findLibrarianByName(name);
cout<<"\n";
if (!(librarian.getName() == Librarian().getName()))
librarian.display();
break;
}
case 2: {
// Option 2: Find a librarian by ID
cout << "enter the ID of the librarian you want to find" << endl;
int id;
cin >> id;
Librarian librarian = Librarian::findLibrarianByID(id);
cout<<"\n";
if (!(librarian.getName() == Librarian().getName()))
librarian.display();
break;
}
default: {
break;
}
}
}