-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
583 lines (473 loc) · 14.8 KB
/
main.cpp
File metadata and controls
583 lines (473 loc) · 14.8 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/*
File:
main.cpp
*/
#include <iostream>
#include <limits>
#include "Patron.h"
#include "Book.h"
#include "AudioCD.h"
#include "DVD.h"
#include "Loan.h"
#include "PatronsCollection.h"
#include "LibraryItemsCollection.h"
#include "LoansCollection.h"
using namespace std;
//Declare collections for patrons, library items, and loans
PatronsCollection patronsCollection;
LibraryItemsCollection libraryItemsCollection; //Collections that handles books, audio CDs, and DVDs
LoansCollection loansCollection;
//A function to display the main menu
void displayMenu()
{
cout << "\nThe Menu:" << endl;
cout << "1. Manage Patrons" << endl;
cout << "2. Manage Library Items" << endl;
cout << "3. Manage Loans" << endl;
cout << "4. Reporting Functions" << endl;
cout << "5. Exit Menu" << endl;
cout << "Choose an option (1 to 5): ";
}
//A function to display the patrons management menu and user input
void patronsMenu()
{
int choice;
do
{
cout << "\nPatrons Management:" << endl;
cout << "1. Add Patron" << endl;
cout << "2. Edit Patron" << endl;
cout << "3. Delete Patron" << endl;
cout << "4. Find Patron" << endl;
cout << "5. Pay Fines" << endl;
cout << "6. Print All Patrons" << endl;
cout << "7. Go Back" << endl;
cout << "Choose an option (1 to 7): ";
cin >> choice;
//Handle user input based on the choice
switch (choice)
{
case 1:
patronsCollection.addPatronsCollection();
break;
case 2:
patronsCollection.editPatronsCollection();
break;
case 3:
patronsCollection.deletePatronsCollection();
break;
case 4:
patronsCollection.findPatronsCollection();
break;
case 5:
patronsCollection.payFinesCollection();
break;
case 6:
patronsCollection.printAllPatronsCollection();
break;
case 7:
cout << "Back to the Menu" << endl;
break;
default:
cout << "Invalid option. Please try again." << endl;
}
}
while (choice != 7); //Loop until the user chooses to go back
}
//A function to display the library items management menu and user input
void libraryItemsMenu(LibraryItemsCollection& libraryItemsCollection)
{
int option;
do
{
cout << "\nLibrary Items Menu:" << endl;
cout << "1. Add Item" << endl;
cout << "2. Edit Item" << endl;
cout << "3. Delete Item" << endl;
cout << "4. Search Item" << endl;
cout << "5. View All Items" << endl;
cout << "6. Exit" << endl;
cout << "Choose an option (1 to 6): ";
cin >> option;
//Handle user input based on the choice
switch (option)
{
//Add Item Optimization
case 1:
{
int itemType;
cout << "\nChoose item type: " << endl;
cout << "1. Book" << endl;
cout << "2. AudioCD" << endl;
cout << "3. DVD" << endl;
cout << "Choose an option (1 to 3): ";
cin >> itemType;
shared_ptr<LibraryItem> newItem = nullptr;
switch (itemType) {
case 1: newItem = make_shared<Book>(); break;
case 2: newItem = make_shared<AudioCD>(); break;
case 3: newItem = make_shared<DVD>(); break;
default:
cout << "Invalid item type." << endl;
continue;
}
newItem->addItem(); //Call addItem for the chosen type
libraryItemsCollection.addLibraryItem(newItem); //Add the item to collection
break;
}
//Edit Item Optimization
case 2:
{
int editItemType;
cout << "\nChoose item type to edit:" << endl;
cout << "1. Book" << endl;
cout << "2. AudioCD" << endl;
cout << "3. DVD" << endl;
cout << "Choose an option (1 to 3): ";
cin >> editItemType;
vector<shared_ptr<LibraryItem>> itemsToEdit;
switch (editItemType)
{
case 1: itemsToEdit = libraryItemsCollection.getItemsByType("Book");
break;
case 2: itemsToEdit = libraryItemsCollection.getItemsByType("AudioCD");
break;
case 3: itemsToEdit = libraryItemsCollection.getItemsByType("DVD");
break;
default:
cout << "Invalid item type." << endl;
continue;
}
if (itemsToEdit.empty())
{
cout << "No items of the selected type found." << endl;
break;
}
//Handle case for editing AudioCD by artist
string artistNameToEdit;
if (editItemType == 2)
{
cout << "\nEnter Audio CD Artist to edit: ";
cin.ignore();
getline(cin, artistNameToEdit);
//Find the AudioCD item to edit by artist name
shared_ptr<AudioCD> audioCDToEdit = nullptr;
for (auto& item : itemsToEdit)
{
auto audioCDItem = dynamic_pointer_cast<AudioCD>(item);
if (audioCDItem && audioCDItem->getArtist() == artistNameToEdit)
{
audioCDToEdit = audioCDItem;
break;
}
}
if (audioCDToEdit == nullptr)
{
cout << "AudioCD with Artist Name " << artistNameToEdit << " not found." << endl;
break;
}
//Display item details before editing
audioCDToEdit->editItem();
}
else if (editItemType == 3) //For DVD, edit by title
{
string dvdTitleToEdit;
cout << "\nEnter DVD title to edit: ";
cin.ignore(); //To clear the newline character from the buffer
getline(cin, dvdTitleToEdit);
//Find the DVD item to edit
shared_ptr<DVD> dvdToEdit = nullptr;
for (auto& item : itemsToEdit)
{
auto dvdItem = dynamic_pointer_cast<DVD>(item);
if (dvdItem && dvdItem->getTitle() == dvdTitleToEdit)
{
dvdToEdit = dvdItem;
break;
}
}
if (dvdToEdit == nullptr)
{
cout << "DVD with Title \"" << dvdTitleToEdit << "\" not found." << endl;
break;
}
//Display item details before editing
dvdToEdit->editItem();
}
else
{
//Handle the case for Book, by Library ID (as before)
int libraryIDToEdit;
cout << "\nEnter the Library ID number of the item to edit: ";
cin >> libraryIDToEdit;
shared_ptr<LibraryItem> itemToEdit = nullptr;
for (auto& item : itemsToEdit)
{
if (item->getLibraryID() == libraryIDToEdit)
{
itemToEdit = item;
break;
}
}
if (itemToEdit == nullptr)
{
cout << "Item with Library ID " << libraryIDToEdit << " not found." << endl;
break;
}
//Display item details before editing
itemToEdit->editItem();
}
break;
}
//Delete Item Optimization
case 3:
{
int deleteItemType;
cout << "\nChoose item type to delete:" << endl;
cout << "1. Book" << endl;
cout << "2. AudioCD" << endl;
cout << "3. DVD" << endl;
cout << "Choose an option (1 to 3): ";
cin >> deleteItemType;
vector<shared_ptr<LibraryItem>> itemsToDelete;
string identifier;
//Holds the Library ID, artist name, or title based on type
switch (deleteItemType)
{
case 1:
//Book deletion
itemsToDelete = libraryItemsCollection.getItemsByType("Book");
if (itemsToDelete.empty())
{
cout << "No Book items found." << endl;
break;
}
cout << "\nEnter the Library ID number of the Book to delete: ";
cin >> identifier;
break;
case 2:
//AudioCD deletion
itemsToDelete = libraryItemsCollection.getItemsByType("AudioCD");
if (itemsToDelete.empty())
{
cout << "No AudioCD items found." << endl;
break;
}
cout << "\nEnter the Artist Name of the AudioCD to delete: ";
cin.ignore();
getline(cin, identifier);
break;
case 3:
//DVD deletion
itemsToDelete = libraryItemsCollection.getItemsByType("DVD");
if (itemsToDelete.empty())
{
cout << "No DVD items found." << endl;
break;
}
cout << "\nEnter the Title of the DVD to delete: ";
cin.ignore();
getline(cin, identifier);
break;
default:
cout << "Invalid item type.\n";
continue;
}
//Delete the item based on identifier and type
bool deleted = libraryItemsCollection.deleteLibraryItem(identifier, deleteItemType);
if (deleted)
{
cout << "The specified item has been deleted." << endl;
}
else
{
cout << "Item is incorrect and not found." << endl;
}
break;
}
//Search Item Optimization
case 4:
{
int itemType;
cout << "\nChoose item type to search:" << endl;
cout << "1. Book" << endl;
cout << "2. AudioCD" << endl;
cout << "3. DVD" << endl;
cout << "Choose an option (1 to 3): ";
cin >> itemType;
string searchTerm;
int libraryID;
switch (itemType)
{
case 1:
//Search by Title for Book
cout << "\nEnter the Library ID number for Book: ";
cin >> libraryID;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
libraryItemsCollection.searchLibraryItemByLibraryID(libraryID);
break;
case 2:
//Search by Artist for AudioCD
cout << "Enter the Artist name: ";
cin.ignore();
getline(cin, searchTerm);
libraryItemsCollection.searchLibraryItemByArtist(searchTerm);
break;
case 3:
//Search by Title for DVD
cout << "Enter the DVD Title: ";
cin.ignore();
getline(cin, searchTerm);
libraryItemsCollection.searchLibraryItemByTitle(searchTerm);
break;
default:
cout << "Invalid option." << endl;
break;
}
break;
}
//Print the Item Optimization
case 5:
libraryItemsCollection.printItemDetails();
break;
//Exit Menu Optimization
case 6:
cout << "Exiting menu." << endl;
break;
//If the Optimization is incorrect
default:
cout << "Invalid option. Please try again." << endl;
}
}
while (option != 6);
}
//A function to display the loans management menu and handle user input
void loansMenu()
{
int choice;
do
{
cout << "\nLoans Management:" << endl;
cout << "1. Add Loan" << endl;
cout << "2. Edit Loan" << endl;
cout << "3. Delete Loan" << endl;
cout << "4. Search/Find Loan" << endl;
cout << "5. Print All Overdue Loans" << endl;
cout << "6. Print Loan Details" << endl;
cout << "7. Go Back" << endl;
cout << "Choose an option (1 to 7): ";
cin >> choice;
//Handle user input based on the choice
switch (choice)
{
case 1:
loansCollection.addLoan();
break;
case 2:
loansCollection.editLoan();
break;
case 3:
loansCollection.deleteLoan();
break;
case 4:
loansCollection.findLoan();
break;
case 5:
loansCollection.printAllOverdueLoans();
break;
case 6:
loansCollection.printAllLoans();
break;
case 7:
cout << "Back to the Menu" << endl;
break;
default:
cout << "Invalid option. Please try again." << endl;
}
}
while (choice != 7); //Loop until the user chooses to go back
}
//Function to display the reporting menu
void reportingMenu()
{
int choice;
do
{
cout << "\nReporting Menu:" << endl;
cout << "1. List All Patrons\n";
cout << "2. List All Library Items\n";
cout << "3. List All Loans\n";
cout << "4. List Overdue Loans\n";
cout << "5. Show Fines Owed by Patrons\n";
cout << "6. Go Back\n";
cout << "Choose an option (1 to 6): ";
cin >> choice;
switch (choice)
{
case 1:
patronsCollection.printAllPatronsCollection();
break;
case 2:
libraryItemsCollection.printItemDetails();
break;
case 3:
loansCollection.printAllLoans();
break;
case 4:
loansCollection.printAllOverdueLoans();
break;
case 5:
for (const auto& patron : patronsCollection.getPatrons())
{
cout << "Patron ID: " << patron.getId()
<< ", Fines Owed: $" << patron.calculateFines() << endl;
}
break;
case 6:
cout << "Back to the Menu" << endl;
break;
default:
cout << "Invalid option. Please try again." << endl;
}
}
while (choice != 6);
}
int main()
{
//A display of the title, my name, and e-mail address
cout << "+-------------------------------------------------+" << endl;
cout << "| Library Management System |" << endl;
cout << "| Author name: Nathanlie Ortega |" << endl;
cout << "| NathanlieOrtega.Dev@gmail.com |" << endl;
cout << "+-------------------------------------------------+\n" << endl;
int choice;
//Loop to display the main menu until the user chooses to exit
do
{
displayMenu();
cin >> choice;
//Handle user input based on the choice
switch (choice)
{
case 1:
patronsMenu();
break;
case 2:
libraryItemsMenu(libraryItemsCollection); //Updated to manage LibraryItems
break;
case 3:
loansMenu();
break;
case 4:
reportingMenu();
break;
case 5:
cout << "Exit Complete" << endl;
break;
default:
cout << "Invalid option, please try again." << endl;
}
}
while (choice != 5); //Loop until the user chooses to exit
return 0;
}