Have you ever wondered how trains are managed at a busy station? What happens when there are only a few tracks and multiple trains arriving and leaving? In this blog post, I’ll walk you through a fun console-based project I built using C++ to simulate train management at a station!
🧠 What Is It?
This is a Train Station Management System written in C++. It lets you:
- Add or delete trains 🚉
- Automatically assign tracks based on arrival times and availability 🎯
- Handle delays and reschedule track allocation ⚙️
- View upcoming trains (with filters!) 📅
🔧 What You Need
- Basic knowledge of C++ (OOP, functions, vectors)
- A C++ compiler like
g++ - A terminal to run the app
🏗️ How It Works
➕ Adding Trains
You can add new trains by providing:
- Train name
- Arrival time (e.g.,
1430means 2:30 PM) - Departure time
- Source and Destination
The system will automatically assign the best available track.
🕒 Delays? No Problem!
If a train is delayed, the system will reallocate tracks and update the schedule.
🔍 View Next Trains
You can see which trains are coming next based on:
- Time
- Number of trains
- Specific track
🗂️ All Trains
Want to see all train details? You can sort them by:
- Arrival time
- Departure time
- Track number
👨💻 How to Run
- Clone the repo
git clone https://github.com/Akataruka/station-management-app.git
cd station-management-app
- Compile the code
g++ -std=c++17 main.cpp -o station-management-app
- Run it
./station-management-app
📸 Demo
WELCOME TO STATION MANAGEMENT APP
1. Create a new Station
Enter station Name: GrandCentral
Enter number of tracks: 2
Station Created ✅
1. Add/Delete trains
2. View Next trains
3. Add delay
4. View all trains
5. Get station details
✨ What I Learned
Priority Queue Interval Processing - Implemented real-time track allocation using min-heaps to efficiently manage overlapping arrival-departure intervals and ensure optimal scheduling.
Timestamp-Based Binary Search - Used binary search on sorted train schedules to quickly identify the next available train based on a user-defined time query.
Function Overloading - Leveraged overloaded functions to support multiple formats of train queries, including time-based, track-based, and count-based filters.
Dynamic Memory Allocation - Created and managed
Trainobjects dynamically using heap allocation, with proper cleanup handled in destructors to prevent memory leaks.Encapsulation - Encapsulated object properties and behaviors within dedicated classes (
Train,Station) to maintain modularity and object-oriented integrity.Command-Line Interface Support - Designed an interactive CLI for querying and managing station operations, providing a smooth user experience for scheduling and reporting.
📌 Want to Try It?
🙌 Final Thoughts
This was a fun and rewarding project. It's simple, educational, and can be extended in many ways like:
- Saving data to files
- Real-time simulation with random train traffic
If you're learning C++ and want to build something cool — give this a try!
Feel free to ask questions or suggest features. 😊
Happy coding! 👨💻👩💻
Top comments (0)