#include <iostream>
#include <vector>
#include <string>
// Class to represent a product
class Product {
public:
Product(const std::string& name, int quantity)
: name(name), quantity(quantity) {}
// Method to get product information
void getInfo() const {
std::cout << name << ": " << quantity << " units\n";
}
// Method to adjust the quantity
void adjustQuantity(int amount) {
quantity += amount;
}
// Method to check if there's enough stock
bool hasStock(int amount) const {
return quantity >= amount;
}
private:
std::string name;
int quantity;
};
// Class to represent a supplier
class Supplier {
public:
Supplier(const std::string& name) : name(name) {}
// Method to supply products to a warehouse
void supply(Product& product, int amount) {
std::cout << name << " supplies " << amount << " units of " << product.getName() << "\n";
product.adjustQuantity(amount);
}
private:
std::string name;
};
// Class to represent a warehouse
class Warehouse {
public:
Warehouse(const std::string& name) : name(name) {}
// Method to store products
void store(Product& product, int amount) {
std::cout << name << " stores " << amount << " units of " << product.getName() << "\n";
product.adjustQuantity(amount);
}
// Method to dispatch products to a retailer
void dispatch(Product& product, int amount) {
if (product.hasStock(amount)) {
std::cout << name << " dispatches " << amount << " units of " << product.getName() << "\n";
product.adjustQuantity(-amount);
} else {
std::cout << name << " does not have enough stock to dispatch " << amount << " units of " << product.getName() << "\n";
}
}
private:
std::string name;
};
// Class to represent a retailer
class Retailer {
public:
Retailer(const std::string& name) : name(name) {}
// Method to receive products from a warehouse
void receive(Product& product, int amount) {
std::cout << name << " receives " << amount << " units of " << product.getName() << "\n";
product.adjustQuantity(amount);
}
private:
std::string name;
};
int main() {
// Create products
Product widget("Widget", 0);
// Create entities in the supply chain
Supplier supplier("Supplier A");
Warehouse warehouse("Warehouse B");
Retailer retailer("Retailer C");
// Simulate the supply chain
supplier.supply(widget, 100);
warehouse.store(widget, 100);
warehouse.dispatch(widget, 50);
retailer.receive(widget, 50);
warehouse.dispatch(widget, 60); // This will fail due to insufficient stock
// Print final stock of the product
widget.getInfo();
return 0;
}