-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory_Management_System.cpp
More file actions
331 lines (280 loc) · 9.39 KB
/
Inventory_Management_System.cpp
File metadata and controls
331 lines (280 loc) · 9.39 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
#include<bits/stdc++.h>
using namespace std;
enum class InventoryOperation {ADD,REMOVE,TRANSFER,ADJUST};
enum class ItemType {ELECTRONICS, GROCERIES, CLOTHING, FURNITURE, OTHER};
//<===========ITEM CLASS===========>
class Item{
string SKU;
string name;
double price;
int quantity;
int threshold;
ItemType type;
public:
string getSKU(){ return SKU; }
string getName(){ return name; }
double getPrice(){ return price; }
int getQuantity(){ return quantity; }
int getThreshold(){ return threshold; }
ItemType getType(){ return type; }
void setSKU(string &sku){ SKU = sku; }
void setName(string &n){ name = n; }
void setPrice(double p){ price = p; }
void setQuantity(int q){ quantity = q; }
void setThreshold(int t){ threshold = t; }
void setType(ItemType t){ type = t; }
};
//<========Clothing Item =========>
class ClothingItem : public Item{
string size;
string color;
public:
ClothingItem(string sku,string name,double price, int quantity,int threshold){
setName(name);
setSKU(sku);
setPrice(price);
setQuantity(quantity);
setThreshold(threshold);
setType(ItemType::CLOTHING);
}
string getSize() {return size;}
string getColor() {return color;}
void setSize(string s){ size = s;}
void setColor(string c){ color = c;}
};
//<========Electronis Item =========>
class ElectronicsItem : public Item{
string brand;
int warranty;
public:
ElectronicsItem(string sku,string name,double price, int quantity,int threshold){
setName(name);
setSKU(sku);
setPrice(price);
setQuantity(quantity);
setThreshold(threshold);
setType(ItemType::ELECTRONICS);
}
string getBrand() {return brand;}
int getWarranty() {return warranty;}
void setBrand(string b){ brand = b;}
void setWarranty(int w){ warranty = w;}
};
//<========Grocery Item =========>
class GroceryItem : public Item{
int shelfLife; // in days
bool isRefrigerated;
string color;
public:
GroceryItem(string sku,string name,double price, int quantity,int threshold){
setName(name);
setSKU(sku);
setPrice(price);
setQuantity(quantity);
setThreshold(threshold);
setType(ItemType::GROCERIES);
}
int getShelfLife() { return shelfLife; }
bool getIsRefrigerated() { return isRefrigerated; }
void setShelfLife(int s){ shelfLife = s;}
void setIsRefrigerated(bool r){ isRefrigerated = r;}
};
class ItemFactory{
public:
Item* createItem(ItemType type, string sku,string name,double price, int quantity,int threshold){
switch(type){
case ItemType::CLOTHING:
return new ClothingItem(sku,name,price,quantity,threshold);
case ItemType::ELECTRONICS:
return new ElectronicsItem(sku,name,price,quantity,threshold);
case ItemType::GROCERIES:
return new GroceryItem(sku,name,price,quantity,threshold);
default:
return new Item();
}
}
};
//========REPLENISHMENT STRATEGY =======>
class ReplenishmentStrategy{
public:
virtual ~ReplenishmentStrategy() = default;
virtual void replenish(Item *item) = 0;
};
class BulkOrder : public ReplenishmentStrategy{
public:
void replenish(Item *item) override {
cout<<"Placing bulk order for item: "<<item->getName()<<endl;
}
};
class JustInTime : public ReplenishmentStrategy{
public:
void replenish(Item *item) override {
cout<<"Placing just-in-time order for item: "<<item->getName()<<endl;
}
};
//=======WAREHOUSE CLASS========
class Warehouse{
int id;
string name;
string location;
map<string,Item*> inventory;
public:
Warehouse(int id,string name){
this->id = id;
this->name = name;
}
int getId() const { return id; }
void setLocation(string loc){ location = loc; }
void addItem(Item *item,int quantity){
string sku = item->getSKU();
if(inventory.find(sku) != inventory.end()){
Item *existing = inventory[sku];
existing->setQuantity(existing->getQuantity() + quantity);
} else {
item->setQuantity(quantity);
inventory[sku] = item;
}
cout<<"Added "<<quantity<<" of "<<item->getName()<<" to warehouse "<<name<<endl;
}
bool removeItem(string sku,int quantity){
if(inventory.find(sku) != inventory.end()){
Item *existing = inventory[sku];
if(existing->getQuantity() >= quantity){
existing->setQuantity(existing->getQuantity() - quantity);
cout<<"Removed "<<quantity<<" of "<<existing->getName()<<" from warehouse "<<name<<endl;
return true;
} else {
cout<<"Insufficient quantity of "<<existing->getName()<<" in warehouse "<<name<<endl;
return false;
}
} else {
cout<<"Item with SKU "<<sku<<" not found in warehouse "<<name<<endl;
return false;
}
}
int getItemQuantity(string sku){
if(inventory.find(sku) != inventory.end()){
return inventory[sku]->getQuantity();
}
return 0;
}
Item* getItem(string sku){
if(inventory.find(sku) != inventory.end()){
return inventory[sku];
}
return nullptr;
}
vector<Item*> getStock(){
vector<Item*> items;
for(auto &p : inventory){
items.push_back(p.second);
}
return items;
}
void printInventory(){
cout<<"Inventory of Warehouse "<<name<<":\n";
for(auto &p : inventory){
Item *item = p.second;
cout<<"SKU: "<<item->getSKU()<<", Name: "<<item->getName()<<", Quantity: "<<item->getQuantity()<<endl;
}
}
};
//========INVENTORY MANAGER CLASS========
class InventoryManager{
vector<Warehouse> warehouses;
ItemFactory itemFactory;
ReplenishmentStrategy *replenishmentStrategy;
public:
InventoryManager(ReplenishmentStrategy *strategy){
replenishmentStrategy = strategy;
}
~InventoryManager(){
delete replenishmentStrategy;
replenishmentStrategy = nullptr;
}
void setReplenishmentStrategy(ReplenishmentStrategy *strategy){
if(replenishmentStrategy != strategy){
delete replenishmentStrategy;
replenishmentStrategy = strategy;
}
}
void addWarehouse(int id,string name){
warehouses.push_back(Warehouse(id,name));
cout<<"Added warehouse: "<<name<<endl;
}
Warehouse* getWarehouse(int id){
for(auto &w : warehouses){
if(w.getId() == id) return &w;
}
return nullptr;
}
bool removeWarehouse(int id){
for(auto it = warehouses.begin(); it != warehouses.end(); it++){
if(it->getId() == id){
warehouses.erase(it);
cout<<"Removed warehouse with id: "<<id<<endl;
return true;
}
}
cout<<"Warehouse with id "<<id<<" not found"<<endl;
return false;
}
Item* getItem(string sku){
for(auto &w : warehouses){
Item *item = w.getItem(sku);
if(item) return item;
}
return nullptr;
}
void checkAndReplenish(string &sku){
Item * item = getItem(sku);
if(item && item->getQuantity() < item->getThreshold()){
replenishmentStrategy->replenish(item);
}
}
void performInventoryCheck(){
for(Warehouse &w : warehouses){
for(Item *item : w.getStock()){
if(item->getQuantity() < item->getThreshold()){
replenishmentStrategy->replenish(item);
}
}
}
}
};
int main(){
ReplenishmentStrategy *replenishmentStrategy = new JustInTime();
// Create an InventoryManager instance
InventoryManager inventoryManager(replenishmentStrategy);
// Create and add warehouses
Warehouse warehouse1(1, "Warehouse 1");
Warehouse warehouse2(2, "Warehouse 2");
inventoryManager.addWarehouse(1, "Warehouse 1");
inventoryManager.addWarehouse(2, "Warehouse 2");
// Create products using ItemFactory
ItemFactory factory;
Item *laptop = factory.createItem(ItemType::ELECTRONICS, "SKU123", "Laptop", 1000.0, 50, 25);
Item *tShirt = factory.createItem(ItemType::CLOTHING, "SKU456", "T-Shirt", 20.0, 200, 100);
Item *apple = factory.createItem(ItemType::GROCERIES, "SKU789", "Apple", 1.0, 100, 200);
// Add products to warehouses
Warehouse *w1 = inventoryManager.getWarehouse(1);
Warehouse *w2 = inventoryManager.getWarehouse(2);
if (w1 && w2) {
w1->addItem(laptop, 15);
w1->addItem(tShirt, 20);
w2->addItem(apple, 50);
}
// Set replenishment strategy to Just-In-Time
inventoryManager.setReplenishmentStrategy(new JustInTime());
// Perform inventory check and replenish if needed
inventoryManager.performInventoryCheck();
// Switch replenishment strategy to Bulk Order
inventoryManager.setReplenishmentStrategy(new BulkOrder());
// Replenish a specific product if needed
string skuToReplenish = "SKU123";
inventoryManager.checkAndReplenish(skuToReplenish);
// Optional: Print final inventories
if (w1) w1->printInventory();
if (w2) w2->printInventory();
return 0;
}