Skip to content

sam-user606/inventory-Manager-

Repository files navigation

Hybrid Inventory Manager

A capstone project demonstrating hybrid C/C++ design: the data layer is written in C (structs + binary file I/O), while the menu, STL, and object-oriented wrapper are written in C++. Data persists across restarts in inventory.dat.


Project structure

capstone/
├── include/
│   ├── inventory.h          # C struct + extern "C" function declarations
│   └── InventoryManager.h   # C++ class declaration
├── src/
│   ├── inventory.c          # C backend (fread/fwrite/fseek)
│   ├── InventoryManager.cpp # C++ wrapper with std::vector + std::sort
│   └── main.cpp             # Console menu + validated input
├── Makefile                 # Primary build system
├── CMakeLists.txt           # Alternative CMake build
└── README.md

Build & run

Option A – Make (recommended)

make          # builds ./inventory_manager
make run      # builds and runs immediately
make clean    # removes build/ and inventory.dat

Requirements: gcc (C11) and g++ (C++17).

Option B – CMake

mkdir build && cd build
cmake ..
cmake --build .
./inventory_manager

Menu

1) Add item
2) View item
3) Update item
4) Delete item
5) List all
6) Exit

List all shows a sort prompt: press 1 (or Enter) to sort by ID, 2 to sort by name.


Input rules

Field Rule
ID Positive integer, unique
Name Non-empty, max 39 characters
Quantity Integer ≥ 0
Price Float ≥ 0

Invalid input prints an error and re-asks — the program never crashes on bad input.


Test cases

  • Add 3 items, exit, restart, list all – Added items with IDs 1, 2, 3, exited, relaunched. List all showed all three items correctly, confirming binary file persistence.

  • Update an item, restart, view it – Updated item 1's name to "Widget Alpha UPDATED", quantity to 99, price to $14.99. After restarting and selecting View item → ID 1, all updated values were displayed correctly.

  • Duplicate ID rejection – Attempted to add a new item with ID 2 (already in use). The program printed [FAIL] Could not add item (ID may already exist) and did not modify the file.

  • Delete an item; confirm it disappears from list and view – Deleted item 2 ("Gadget Beta"). Listing all showed only items 1 and 3. Attempting to view item 2 printed [FAIL] Item not found or has been deleted.

  • Invalid input recovery – Entered -5 for ID, abc for quantity, and empty string for name at various prompts. The program re-prompted every time without crashing, then accepted correct values on the next attempt.


Design notes

Concern Language Mechanism
File I/O C fread / fwrite / fseek on a binary flat file
Soft delete C is_deleted flag set to 1 in-place via fseek
Duplicate guard C get_item scan before fwrite in add_item
Listing C++ std::vector<Item> populated from list_items()
Sorting C++ std::sort with lambda comparators
Linkage C++ extern "C" block in inventory.h

About

inventory management system using C and C++ with binary file storage and CRUD operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors