BHARATI VIDYAPEETH COLLEGE OF ENGINEERING
NEW DELHI
Object Oriented Programming Using C++
Session: 2023 – 27
PROJECT-BASED LEARNING
Stock Management System
Submitted To: Submitted By:
Mrs. Neha Sharma Raman Bajaj
Prof. (Object Oriented Programming Using C++) IT – 1 (Sem 3)
01311503123
SOURCE CODE
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> // for std::setw
using namespace std;
class Product
public:
string name, SKU, category, supplier;
double cost, sellingPrice;
int stockQuantity;
Product(string n, string sku, string cat, string sup, double c, double sp, int sq)
: name(n), SKU(sku), category(cat), supplier(sup), cost(c), sellingPrice(sp), stockQuantity(sq) {}
void display() const
cout << "SKU: " << SKU << " | Name: " << setw(10) << name
<< " | Category: " << setw(10) << category << " | Stock Quantity: "
<< setw(4) << stockQuantity;
if (stockQuantity < 5)
cout << " ** Warning: Low Stock! **";
cout << endl;
};
class StockManagementSystem
{
private:
vector<Product> products;
map<string, vector<string>> alerts; // SKU -> alerts
public:
void dashboard()
cout << "\n--- Dashboard ---\n";
int totalStock = 0;
for (const auto &p : products)
totalStock += p.stockQuantity;
if (p.stockQuantity < 5)
alerts[p.SKU].push_back("Low stock");
cout << "Total Stock: " << totalStock << endl;
cout << "---------------------------------------\n";
cout << "Low Stock Items:\n";
for (const auto &p : products)
if (p.stockQuantity < 5)
cout << "- SKU: " << p.SKU << " (Item: " << p.name << ") - Low Stock Alert (Quantity: "
<< p.stockQuantity << ")\n";
cout << "---------------------------------------\n";
void addProduct()
string name, sku, category, supplier;
double cost, sellingPrice;
int stockQuantity;
cout << "\n--- Add Product ---\n";
cout << "Enter Product Name: ";
cin >> name;
cout << "Enter SKU: ";
cin >> sku;
cout << "Enter Category: ";
cin >> category;
cout << "Enter Supplier: ";
cin >> supplier;
cout << "Enter Cost: ";
cin >> cost;
cout << "Enter Selling Price: ";
cin >> sellingPrice;
cout << "Enter Stock Quantity: ";
cin >> stockQuantity;
products.emplace_back(name, sku, category, supplier, cost, sellingPrice, stockQuantity);
cout << "\nProduct added successfully!\n";
void updateProduct()
string sku;
cout << "\n--- Update Product ---\n";
cout << "Enter SKU of product to update: ";
cin >> sku;
for (auto &p : products)
if (p.SKU == sku)
cout << "\nUpdating Product Details for SKU: " << sku << endl;
cout << "---------------------------------------\n";
cout << "Enter new name (current: " << p.name << "): ";
cin >> p.name;
cout << "Enter new category (current: " << p.category << "): ";
cin >> p.category;
cout << "Enter new supplier (current: " << p.supplier << "): ";
cin >> p.supplier;
cout << "Enter new cost (current: $" << p.cost << "): ";
cin >> p.cost;
cout << "Enter new selling price (current: $" << p.sellingPrice << "): ";
cin >> p.sellingPrice;
cout << "Enter new stock quantity (current: " << p.stockQuantity << "): ";
cin >> p.stockQuantity;
cout << "\nProduct updated successfully!\n";
return;
cout << "Product not found.\n";
void deleteProduct()
string sku;
cout << "\n--- Delete Product ---\n";
cout << "Enter SKU of product to delete: ";
cin >> sku;
auto it = remove_if(products.begin(), products.end(), [&sku](const Product &p)
{ return p.SKU == sku; });
if (it != products.end())
cout << "\nAre you sure you want to delete product " << sku << "? (y/n): ";
char confirm;
cin >> confirm;
if (confirm == 'y')
{
products.erase(it, products.end());
cout << "Product deleted successfully!\n";
else
cout << "Deletion cancelled.\n";
else
cout << "Product not found.\n";
void viewStockLevels()
cout << "\n--- Stock Levels ---\n";
cout << "---------------------------------------\n";
for (const auto &p : products)
p.display();
cout << "---------------------------------------\n";
void createOrder()
string sku;
int quantity;
cout << "\n--- Create Order ---\n";
cout << "Enter SKU of product to order: ";
cin >> sku;
cout << "Enter quantity: ";
cin >> quantity;
for (auto &p : products)
if (p.SKU == sku)
if (p.stockQuantity >= quantity)
p.stockQuantity -= quantity;
cout << "\nOrder created successfully!\n";
cout << "Remaining stock for " << p.name << " (SKU: " << sku << "): " << p.stockQuantity << "\n";
else
cout << "Insufficient stock! Only " << p.stockQuantity << " available.\n";
return;
cout << "Product not found.\n";
void viewOrderHistory()
cout << "\n--- Order History ---\n";
cout << "---------------------------------------\n";
cout << "No orders to display.\n"; // Placeholder for simplicity
cout << "---------------------------------------\n";
void generateInvoice()
cout << "\n--- Generate Invoice ---\n";
cout << "---------------------------------------\n";
cout << "Invoice #0001\n";
cout << "Date: 2024-11-01\n";
cout << "---------------------------------------\n";
cout << "Product | SKU | Quantity | Price | Total\n";
cout << "WidgetB | P002 | 5 | $28.00 | $140.00\n";
cout << "---------------------------------------\n";
cout << "Subtotal: $140.00\n";
cout << "Tax (10%): $14.00\n";
cout << "Total: $154.00\n";
cout << "---------------------------------------\n";
cout << "Thank you for your purchase!\n";
void run()
while (true)
cout << "\n--- Stock Management System ---\n";
cout << "1. Dashboard\n2. Add Product\n3. Update Product\n4. Delete Product\n";
cout << "5. View Stock Levels\n6. Create Order\n7. View Order History\n8. Generate Invoice\n9. Exit\n";
int choice;
cout << "Enter choice: ";
cin >> choice;
switch (choice)
case 1:
dashboard();
break;
case 2:
addProduct();
break;
case 3:
updateProduct();
break;
case 4:
deleteProduct();
break;
case 5:
viewStockLevels();
break;
case 6:
createOrder();
break;
case 7:
viewOrderHistory();
break;
case 8:
generateInvoice();
break;
case 9:
cout << "Exiting system.\n";
return;
default:
cout << "Invalid choice!\n";
};
int main()
StockManagementSystem sms;
sms.run();
return 0;
}
OUTPUT
Dashboard:
Add Product:
Update Product:
Delete Product:
View Stock Levels:
Create Order:
View Order History:
Generate Invoice: