Repository navigation
Expand file tree
/
Copy pathDonationSystem.cpp
More file actions
64 lines (54 loc) · 1.76 KB
/
Copy pathDonationSystem.cpp
File metadata and controls
64 lines (54 loc) · 1.76 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
#include "DonationSystem.h"
#include <iostream>
DonationSystem::DonationSystem() {}
void DonationSystem::addUser(User* user) {
users.push_back(user);
}
User* DonationSystem::login(std::string email, std::string password) {
for (auto u : users) {
if (u->getEmail() == email && u->getPassword() == password) {
return u;
}
}
return nullptr;
}
void DonationSystem::addToPool(DonationItem donation) {
donationPool[donation.getItemName()] += donation.getQuantity();
}
void DonationSystem::addRequest(RequestedItem request) {
pendingRequests.push_back(request);
}
void DonationSystem::processRequests() {
for (auto it = pendingRequests.begin(); it != pendingRequests.end();) {
std::string name = it->getItemName();
int qty = it->getQuantity();
if (donationPool[name] >= qty) {
donationPool[name] -= qty;
approvedRequests.push_back(*it);
it = pendingRequests.erase(it);
} else {
++it;
}
}
}
void DonationSystem::approveRequestManually(int index) {
if (index >= 0 && index < pendingRequests.size()) {
RequestedItem request = pendingRequests[index];
std::string name = request.getItemName();
int qty = request.getQuantity();
if (donationPool[name] >= qty) {
donationPool[name] -= qty;
approvedRequests.push_back(request);
pendingRequests.erase(pendingRequests.begin() + index);
}
}
}
std::map<std::string, int> DonationSystem::getDonationPool() {
return donationPool;
}
std::vector<RequestedItem> DonationSystem::getPendingRequests() {
return pendingRequests;
}
std::vector<RequestedItem> DonationSystem::getApprovedRequests() {
return approvedRequests;
}