#include <bits/stdc++.h>
using namespace std;
// Define the inventory class
class Inventory {
private:
unordered_map<string, int> items; // Hash table to store items and their quantities
int total_inventory; // Total inventory count
public:
// Constructor
Inventory() {
total_inventory = 0;
}
// Add an item to the inventory
void add_item(string item_name, int quantity) {
if (items.find(item_name) == items.end()) {
// If the item doesn't exist in the inventory, add it
items[item_name] = quantity;
total_inventory += quantity;
} else {
// If the item already exists, update its quantity
int old_quantity = items[item_name];
items[item_name] = old_quantity + quantity;
total_inventory += quantity;
}
}
// Remove an item from the inventory
void remove_item(string item_name, int quantity) {
if (items.find(item_name) != items.end()) {
// If the item exists in the inventory, update its quantity
int old_quantity = items[item_name];
if (old_quantity > quantity) {
items[item_name] -= quantity;
total_inventory -= quantity;
} else {
// If the quantity to remove is greater than the current quantity, remove the item completely
items.erase(item_name);
total_inventory -= old_quantity;
}
}
}
// Check the quantity of a specific item in the inventory
int check_quantity(string item_name) {
if (items.find(item_name) != items.end()) {
// If the item exists in the inventory, return its quantity
return items[item_name];
} else {
// If the item doesn't exist in the inventory, return 0
return 0;
}
}
// Display the total inventory count
int get_total_inventory() {
return total_inventory;
}
};
int main() {
Inventory site_inventory;
// Add items to the inventory
site_inventory.add_item("T-shirt", 100);
site_inventory.add_item("Shoes", 50);
site_inventory.add_item("Book", 30);
// Remove items from the inventory
site_inventory.remove_item("T-shirt", 30);
site_inventory.remove_item("Book", 15);
// Check the quantity of specific items
cout << "Quantity of T-shirt: " << site_inventory.check_quantity("T-shirt") << endl;
cout << "Quantity of Shoes: " << site_inventory.check_quantity("Shoes") << endl;
cout << "Quantity of Book: " << site_inventory.check_quantity("Book") << endl;
// Display the total inventory count
cout << "Total inventory: " << site_inventory.get_total_inventory() << endl;
return 0;
}