C++ Inventory Management Program
This program manages a simple inventory system where you can:
1. Add new items to the inventory.
2. Update the quantity of existing items.
3. Display all stored items.
4. Sell items by reducing their quantity.
5. View the total sold items (not fully implemented in this version).
The program uses classes and arrays to store data for items, including their code, quantity, and
price.
#include <iostream>
#include <conio.h> // For getch()
using namespace std;
const int MAX_ITEMS = 20;
class Department {
int amount[MAX_ITEMS], price[MAX_ITEMS],
code[MAX_ITEMS]; int last; // Keeps track of the last
item added
public:
Department() {
last = 0;
for (int i = 0; i < MAX_ITEMS; i++) {
amount[i] = 0;
price[i] = 0;
code[i] = 0;
}
}
void addOldItem();
void addNewItem();
void showItems();
void sellItem();
void totalItemsSold();
};
// Add details to an existing
item void
Department::addOldItem() {
int itemCode, quantity;
cout << "\nEnter item code:
"; cin >> itemCode;
cout << "Enter quantity to add:
"; cin >> quantity;
for (int i = 0; i < last;
i++) { if (code[i] ==
itemCode) {
amount[i] += quantity;
cout << "Item updated
successfully.\n"; return;
}
}
cout << "Item not found.\n";
}
// Add a completely new item
void
Department::addNewItem() {
if (last >= MAX_ITEMS) {
cout << "No space to add more items.\n";
return;
}
cout << "\nEnter item code:
"; cin >> code[last];
cout << "Enter quantity:
"; cin >> amount[last];
cout << "Enter price:
"; cin >> price[last];
last++;
cout << "New item added successfully.\n";
}
// Display all items
void Department::showItems()
{ if (last == 0) {
cout << "No items to display.\n";
return;
}
cout << "\n--- List of Items ---
\n";
for (int i = 0; i < last; i++) {
cout << "Code: " << code[i]
<< ", Quantity: " << amount[i]<< ", Price: " << price[i] << endl;
}
}
// Sell an item
void Department::sellItem()
{ int itemCode, quantity;
cout << "\nEnter item code:
"; cin >> itemCode;
cout << "Enter quantity to sell:
"; cin >> quantity;
for (int i = 0; i < last;
i++) { if (code[i] ==
itemCode) {
if (amount[i] >= quantity)
{ amount[i] -=
quantity;
cout << "Item sold successfully. Total: " << quantity* price[i] << endl;
} else {
Cout<<”Not enough Stock Available\n”<<endl;
}
}
cout << "Item not found.\n";
}
// Show total items sold
void Department::totalItemsSold() {
cout << "\nFeature not implemented in this version.\n";
}
int main() {
Department d;
int choice;
do {
cout << "\n--- Menu ---\n";
cout << "1. Show all stored
items\n"; cout << "2. Add an old
item\n";
cout << "3. Add a new
item\n"; cout << "4. Sell an
item\n"; cout << "5. Total
sold items\n"; cout << "6.
Quit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
d.showItems();
break;
case 2:
d.addOldItem();
break;
case 3:
d.addNewItem();
break;
case 4:
d.sellItem();
break;
case 5:
d.totalItemsSold();
break;
case 6:
cout << "Exiting program.\n";
break;
default:
cout << "Invalid choice. Try again.\n";
}
} while (choice != 6);
getch(); // To pause the
screen return 0;
}
OUTPUT:
Menu
1. Show all stored items
2. Add an old item
3. Add a new item
4. Sell an item
5. Total sold items
6. Quit
Enter your choice: 3
Enter item code: 101
Enter quantity: 50
Enter price: 20
New item added successfully.
Menu
1. Show all stored items
2. Add an old item
3. Add a new item
4. Sell an item
5. Total sold items
61 Quit
Enter your choice: 1
List of Items
Code: 101, Quantity: 50, Price: 20