🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

Image
  🌿  Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms" 🧭  1. Introduction: Farming in the Age of Climate Change In a world where clean water is more precious than gold, efficient  rainwater harvesting and plant care systems  are no longer optional — they’re essential. Smart farming doesn’t mean just automating irrigation. It means combining  robotic drones, environmental sensors, and intelligent scheduling  to build a garden that practically takes care of itself. In this guide, we build a  fully functional Garden Manager System  using  C++  that: Captures and conserves rainwater Uses  robotic drones and sensors  to monitor crop health Integrates a  real-time UI  with progress bars and alerts Includes  timers  for scheduling plant growth and drone tasks Plays  interactive sounds  based on crop state and events Whether you'r...

C++ Mini Projects: Simple Inventory Management

C++ Mini Projects: Simple Inventory Management

Hey guys, I am back with another cool project. This is going to be a simple inventory management system where the program allows the user to manage the inventory of a shop or store by adding, updating, and deleting products. Also, features like searching for different products by name or number, calculating the inventory's total product value, and saving and loading inventory data from files will be available. Let's go build this project.

Skills Used

Classes

  • Details of products and inventory

Vectors

  • Managing a list of products

File Handling

  • Saving and loading inventory data

Input and Output

  • Interaction with users and displaying data

The Code to Build the Desired Project

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

// Product class
class Product {
public:
    int id;
    string name;
    int quantity;
    double price;

    Product(int id, const string& name, int quantity, double price)
        : id(id), name(name), quantity(quantity), price(price) {}
};

// Inventory Management Class
class Inventory {
private:
    vector<Product> products;
    int nextID;

public:
    Inventory() : nextID(1) {}

    // Add a new product
    void addProduct() {
        string name;
        int quantity;
        double price;

        cout << "Enter product name: ";
        cin.ignore();
        getline(cin, name);
        cout << "Enter quantity: ";
        cin >> quantity;
        cout << "Enter price: ";
        cin >> price;

        products.emplace_back(nextID++, name, quantity, price);
        cout << "Product added successfully!\n";
    }

    // Update a product
    void updateProduct() {
        int id;
        cout << "Enter product ID to update: ";
        cin >> id;

        for (auto& product : products) {
            if (product.id == id) {
                cout << "Enter new name (current: " << product.name << "): ";
                cin.ignore();
                getline(cin, product.name);
                cout << "Enter new quantity (current: " << product.quantity << "): ";
                cin >> product.quantity;
                cout << "Enter new price (current: " << product.price << "): ";
                cin >> product.price;

                cout << "Product updated successfully!\n";
                return;
            }
        }
        cout << "Product with ID " << id << " not found.\n";
    }

    // Delete a product
    void deleteProduct() {
        int id;
        cout << "Enter product ID to delete: ";
        cin >> id;

        for (auto it = products.begin(); it != products.end(); ++it) {
            if (it->id == id) {
                products.erase(it);
                cout << "Product deleted successfully!\n";
                return;
            }
        }
        cout << "Product with ID " << id << " not found.\n";
    }

    // Search for a product by name
    void searchProduct() const {
        string name;
        cout << "Enter product name to search: ";
        cin.ignore();
        getline(cin, name);

        for (const auto& product : products) {
            if (product.name == name) {
                cout << "Product found:\n";
                cout << "ID: " << product.id << ", Name: " << product.name
                     << ", Quantity: " << product.quantity << ", Price: " << product.price << "\n";
                return;
            }
        }
        cout << "Product with name \"" << name << "\" not found.\n";
    }

    // Calculate total inventory value
    void calculateTotalValue() const {
        double totalValue = 0;
        for (const auto& product : products) {
            totalValue += product.quantity * product.price;
        }
        cout << "Total inventory value: " << totalValue << "\n";
    }

    // Save inventory to a file
    void saveToFile() const {
        ofstream outFile("inventory.txt");
        if (!outFile) {
            cout << "Error saving inventory data.\n";
            return;
        }

        for (const auto& product : products) {
            outFile << product.id << "\n"
                    << product.name << "\n"
                    << product.quantity << "\n"
                    << product.price << "\n";
        }
        outFile.close();
        cout << "Inventory saved successfully!\n";
    }
};

int main() {
    Inventory inventory;
    inventory.loadFromFile();
    int choice;

    do {
        cout << "\nSimple Inventory Management\n";
        cout << "1. Add Product\n";
        cout << "2. Update Product\n";
        cout << "3. Delete Product\n";
        cout << "4. Search Product\n";
        cout << "5. Calculate Total Value\n";
        cout << "6. Display All Products\n";
        cout << "7. Save and Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
            case 1:
                inventory.addProduct();
                break;
            case 2:
                inventory.updateProduct();
                break;
            case 3:
                inventory.deleteProduct();
                break;
            case 4:
                inventory.searchProduct();
                break;
            case 5:
                inventory.calculateTotalValue();
                break;
            case 6:
                inventory.displayProducts();
                break;
            case 7:
                inventory.saveToFile();
                cout << "Exiting program. Goodbye!\n";
                break;
            default:
                cout << "Invalid choice. Please try again.\n";
        }
    } while (choice != 7);

    return 0;
}

Real-World Examples

Supermarkets and Retail Stores

Inventory systems are crucial for retail stores and supermarkets. They allow managers to track stock levels, details of products, and place reorders on time to prevent stock-out issues.

Distribution Centers and Warehouses

Large distribution centers and warehouses utilize similar mechanisms for tracking hundreds of products efficiently.

E-Commerce Platforms

Virtual stores depend on inventory systems to update products in real-time, handle large orders, and manage pricing effectively.

Problem-Solving Approaches

Dealing with Dynamic Data

  • Using vectors to dynamically store and manage products.
  • Implementing file handling for persistent data across multiple sessions.

Optimization of Update and Search Systems

  • Utilizing linear search in vectors for efficient product lookup.
  • Considering hash tables for larger inventories to speed up lookups.

Data Consistency

  • Validating user input to avoid incorrect price and quantity entries.
  • Automating ID generation to maintain unique product identifiers.

Maintainability and Scalability

  • Modularizing the code into functions and classes for easy updates and expansion.

Comments

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

C++ Projects: Password Manager