-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryCustomer.cpp
More file actions
102 lines (88 loc) · 3.36 KB
/
Copy pathLibraryCustomer.cpp
File metadata and controls
102 lines (88 loc) · 3.36 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
//
// Created by isido on 11/28/2023.
//
#include "LibraryCustomer.h"
#include <iostream>
#include <stdexcept>
using namespace std;
LibraryCustomer::LibraryCustomer(const string& identifier, const string& customerName, int contact)
: uniqueIdentifier(identifier), name(customerName), contactInfo(contact) {}
string LibraryCustomer::getUniqueIdentifier() const{
return uniqueIdentifier;
}
string LibraryCustomer::getName() const{
return name;
}
int LibraryCustomer::getContactInfo() const{
return contactInfo;
}
void LibraryCustomer::setUniqueIdentifier(const string& identifier) {
uniqueIdentifier = identifier;
}
void LibraryCustomer::setName(const string& customerName) {
name = customerName;
}
void LibraryCustomer::setContactInfo(int contact) {
contactInfo = contact;
}
list<ItemsInLibrary> LibraryCustomer::getCheckedOutItems () const {
return checkedOutItems;
}
void LibraryCustomer::cust_CheckedOutItem(ItemsInLibrary &item, int returnDueDate) {
if (item.isCheckedOut()) {
item.checkOut();
checkedOutItems.push_back(item);
returnDueDates.push(returnDueDate);
} else {
cout << "Item is already checked out." << endl;
// cout << "Signed: "<< staff.getStaffName()<<endl;
}
}
void LibraryCustomer::returnItemBeforeDueDate(ItemsInLibrary& item) {
if (!item.isCheckedOut()) {
cout << "Item is not checked out." << endl;
// cout <<"Signed: "<< staff.getStaffName();
return;
}
int dueDate = 5; // Assuming dueDate is 5 for demonstration
int currentDate = 0; // Replace with actual current date logic
try {
if (currentDate < dueDate) {
item.returnItem();
// Find the item in the checkedOutItems list and remove it
for (auto it = checkedOutItems.begin(); it != checkedOutItems.end(); ++it) {
if (it->getItemUniqueID() == item.getItemUniqueID()) {
cout << "Item being returned before due date: " << it->getItemTitle() << endl;
checkedOutItems.erase(it);
break;
}
}
returnDueDates.pop();
cout << "NOTE: ITEM RETURNED BEFORE DUE DATE!\n" << endl;
} else {
// Find the item in the checkedOutItems list and print it as returned after due date
for (const auto& checkedItem : checkedOutItems) {
if (checkedItem.getItemUniqueID() == item.getItemUniqueID()) {
cout << "Item returned after due date: " << checkedItem.getItemTitle() << endl;
break;
}
}
throw runtime_error("Item cannot be returned after the due date has passed.");
}
} catch (const exception& e) {
cout << "Exception occurred: " << e.what() << endl;
}
// Print the current list of checked-out items after the return
cout << "Currently checked-out items:" << endl;
for (const auto& checkedItem : checkedOutItems) {
cout << checkedItem.getItemTitle() << endl;
}
}
void LibraryCustomer::printCustomerInfo() {
cout << "\n=== Customers Info ===" << endl;
cout << "Customer ID: " << uniqueIdentifier << endl;
cout << "Name: " << name << endl;
cout << "Contact Info: " << contactInfo << endl;
cout << "Checked Out Items: " << checkedOutItems.size() << endl;
cout << "\n";
}