Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Food Ordering System — a file-driven ordering, inventory, payment, and receipt workflow

A fundamentals-first C++ console application built around the complete lifecycle of a restaurant order.

Run it  ·   System flow  ·   Project structure  ·   More projects

Why this exists

This project explores how a small real-world workflow can be decomposed into clear C++ responsibilities. It loads menu data from a text file, guides multiple customers through ordering and payment, updates in-memory stock, and appends formatted receipts without overwriting earlier orders.

The interesting part is not the menu screen. It is the state and error handling behind it.

What the system handles

Area Behavior
Menu ingestion Parses IDs, names, prices, and quantities from Menu.txt
Inventory Shows available items and reduces stock as orders are accepted
Input recovery Clears failed input streams and re-prompts for non-numeric or invalid values
Order validation Rejects unknown IDs, unavailable items, invalid quantities, and oversized orders
Payments Supports cash, card, and eWallet paths; cash includes amount and change validation
Receipts Generates order IDs and appends formatted order details to receipt.txt
Sessions Processes multiple tables/customers until the operator exits

System flow

flowchart LR
    A[Load Menu.txt] --> B{Valid menu?}
    B -- No --> X[Stop with file error]
    B -- Yes --> C[Start customer]
    C --> D[Display in-stock menu]
    D --> E[Collect and validate items]
    E --> F[Reduce inventory]
    F --> G[Calculate total]
    G --> H{Payment method}
    H -->|Cash| I[Validate amount and change]
    H -->|Card| J[Confirm card payment]
    H -->|eWallet| K[Confirm eWallet payment]
    I --> L[Append receipt]
    J --> L
    K --> L
    L --> M{Another customer?}
    M -- Yes --> C
    M -- No --> N[Exit]
Loading

A quick look

Full Menu in Stock

ID   Item                        Price  Quantity
------------------------------------------------
1    Chicken Burger               7.50        10
2    French Fries                 3.00        15

Please Enter Menu ID or Press '0' to Finish: 1
Select From 1 to 10
Enter Quantity: 2

Total Amount: RM 15.00
Payment successful! Change: RM 5.00
Saved receipt for Order ID: 59

Run it

Requirements

  • A C++ compiler with standard library support, such as g++
  • A terminal or PowerShell window

Build

git clone https://github.com/xrobinx/cpp-food-ordering.git
cd cpp-food-ordering
g++ header.cpp driver.cpp -o food_ordering

Run on macOS/Linux:

./food_ordering

Run on Windows:

.\food_ordering.exe

Keep Menu.txt in the same working directory as the executable.

Menu data format

Each menu item uses this delimiter-based format:

id,name;price&quantity

Example:

1,Chicken Burger;7.50&10
Value Meaning
1 Menu ID
Chicken Burger Display name
7.50 Unit price
10 Available quantity

Project structure

cpp-food-ordering/
├── driver.cpp    # Main customer and payment workflow
├── header.cpp    # Parsing, ordering, totals, receipts, and order IDs
├── header.h      # Data structures, limits, and function declarations
├── Menu.txt      # File-backed menu and starting inventory
├── receipt.txt   # Appended receipt output
└── README.md

Core data structures

struct MenuItem {
    int menuId;
    std::string name;
    double price;
    int qty;
};

struct OrderLine {
    int OrderId;
    int OrderQty;
};

The code separates orchestration in driver.cpp from reusable operations in header.cpp. The local parseLine helper is kept file-scoped with static, while declarations and shared data types live in header.h.

Receipt output

Receipts are opened with ios::app, so a new transaction is added instead of replacing existing data.

Order ID: 59 | Table: 1
---------------------------------------------------------------
ID   Item                       Quantity     Price        Line
1    Chicken Burger                   2       7.50       15.00
2    French Fries                     1       3.00        3.00
---------------------------------------------------------------
Total: RM 18.00
Payment Method: Cash
Change: RM 2.00

Engineering notes

This version deliberately stays close to core language features: fixed-size arrays, structs, functions, nested validation loops, stream recovery, file streams, and formatted output.

Good next iterations would be:

  • Replace fixed arrays with std::vector
  • Represent payment choices with an enum class
  • Persist updated inventory between program runs
  • Separate UI, domain logic, and storage into dedicated classes
  • Add unit tests for parsing, totals, stock, and payment validation
  • Add a build system such as CMake

Author

Built by Robin, a Bachelor of Computer Science candidate exploring software engineering from strong fundamentals.

GitHub · LinkedIn · Email

About

A simple C++ console-based food ordering system that reads menu data from a file, manages orders and stock, handles payments, and generates receipts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages