A comprehensive command-line metro transit management system with fare calculation, pass management, and journey tracking.
Features • Installation • Usage • Architecture • Documentation
- Overview
- Features
- System Architecture
- Installation
- Usage
- Pass Types
- Zone & Fare Matrix
- Code Structure
- Error Handling
- Data Persistence
- Contributing
- License
SmartTransit is an object-oriented metro transit system designed to manage metro passes, calculate fares based on zones, track journey history, and provide a seamless user experience through a colorful command-line interface. Built with modern C++ practices, it demonstrates polymorphism, file I/O, and robust error handling.
- User-Friendly: Intuitive menu-driven interface with colored output
- Flexible Pricing: Dynamic fare calculation based on zones and pass types
- Discount System: Automatic discounts for students (30% off) and seniors (50% off)
- Journey Tracking: Persistent storage of all journey records with timestamps
- Robust: Comprehensive input validation and error handling
- Create Passes: Generate unique passes for students, seniors, and regular passengers
- View All Passes: Display detailed information about all registered passes
- Recharge Passes: Add balance to existing passes with validation
- Auto-Generated IDs: Unique identifier system (STU-xxx, SNR-xxx, REG-xxx)
- Zone-Based Travel: Support for 5 zones (A, B, C, D, E)
- Fare Calculation: Automatic fare computation based on distance
- Balance Validation: Prevents travel with insufficient funds
- Real-Time Receipts: Instant journey confirmation with details
- Journey History: View all past journeys with timestamps
- Persistent Storage: CSV-based storage in
journeys.txt - Auto-Loading: Historical data loaded on startup
- Colored Output: ANSI color support for better readability
- Visual Elements: Unicode box-drawing characters for menus
- Status Indicators: ✔ (success) and ✖ (error) symbols
- Clear Messaging: Descriptive error and success messages
Pass (Abstract Base Class)
├── StudentPass (30% discount)
├── SeniorPass (50% discount)
└── RegularPass (no discount)
TransitSystem (Main Controller)
├── Pass Management
├── Journey Creation
├── History Tracking
└── File Operations
Journey (Data Model)
├── Zone Information
├── Fare Details
└── Timestamp
- Polymorphism: Virtual
calculateFare()method for different pass types - Encapsulation: Private data members with controlled access
- Inheritance: Pass hierarchy with specialized behavior
- Operator Overloading:
+=operator for recharge functionality
- C++ Compiler: g++ with C++11 support or later
- Operating System: Linux, macOS, or Windows with WSL
- Terminal: Support for ANSI escape codes (modern terminals)
# Clone the repository
git clone https://github.com/LalithSecondary/TransistSystem.git
cd SmartTransit
# Compile the program
g++ -o metro main.cpp -std=c++11
# Run the application
./metro-o metro: Output executable named "metro"-std=c++11: Use C++11 standard features
When you launch the application, you'll see:
╔══════════════════════════════════╗
║ SMART METRO TRANSIT SYSTEM ║
╚══════════════════════════════════╝
1. Create Pass
2. View Passes
3. Start Journey
4. View History
5. Recharge
0. Exit
> 1
Name: Alice
Age: 19
Initial Balance: 100
1. Student
2. Senior
3. Regular
> 1
✔ Pass Created!
===== PASS INFO =====
Name : Alice
Age : 19
ID : STU-1
Type : STUDENT
Balance : 100
> 3
Pass ID: STU-1
From (A-E): A
To (A-E): C
✔ Fare Deducted: 17.5
--- Journey Receipt ---
From : A
To : C
Fare : 17.5
Time : 21-11-2025 12:30
> 5
Enter Pass ID: STU-1
Amount: 50
✔ New Balance: 132.5
| Pass Type | Prefix | Discount | Use Case |
|---|---|---|---|
| Student | STU- | 30% off | Students with valid ID |
| Senior | SNR- | 50% off | Senior citizens (60+) |
| Regular | REG- | No discount | General public |
Base Fare: ₹25 (Zone A to Zone C)
- Student Pass: ₹25 × 0.70 = ₹17.5
- Senior Pass: ₹25 × 0.50 = ₹12.5
- Regular Pass: ₹25.0
A ←→ B ←→ C ←→ D ←→ E
| A | B | C | D | E | |
|---|---|---|---|---|---|
| A | 0 | 15 | 25 | 35 | 45 |
| B | 15 | 0 | 20 | 30 | 40 |
| C | 25 | 20 | 0 | 25 | 35 |
| D | 35 | 30 | 25 | 0 | 25 |
| E | 45 | 40 | 35 | 25 | 0 |
Note: Fares are symmetrical (A→B = B→A)
SmartTransit/
├── main.cpp # Entry point & menu system
├── TransitSystem.cpp # Core system logic
├── Pass.cpp # Pass classes (Student, Senior, Regular)
├── Journey.cpp # Journey data model
├── colors.hpp # ANSI color definitions & utilities
├── journeys.txt # Persistent journey history (auto-generated)
├── metro # Compiled executable
└── README.md # This file
- Application entry point
- Menu-driven interface
- Input validation and error handling
- ANSI color initialization
- Central controller class
- Pass creation and management
- Journey processing
- File I/O operations
- Fare calculation logic
- Abstract
Passbase class StudentPass,SeniorPass,RegularPassderived classes- Virtual fare calculation methods
- Balance management
- Journey data structure
- Timestamp generation
- CSV serialization
- Display formatting
- ANSI escape code definitions
- Color constants (RED, GREEN, YELLOW, BLUE, CYAN)
- Formatting (BOLD, RESET)
- Special symbols (TICK ✔, CROSS ✖)
enableANSI()function for Windows compatibility
SmartTransit includes comprehensive error handling:
| Validation Type | Check | Error Message |
|---|---|---|
| Menu Choice | Numeric input | "Invalid input! Please enter a number." |
| Age | Positive integer | "Invalid age!" |
| Balance | Non-negative number | "Invalid balance!" |
| Pass Type | 1-3 range | "Invalid choice!" |
| Zone | A-E only | "Invalid zone! Please enter A-E." |
| Amount | Positive number | "Invalid amount!" |
- Duplicate Zones: Prevents same start/end zone
- Insufficient Balance: Checks before journey
- Pass Not Found: Validates pass ID existence
- Empty Lists: Graceful handling of no passes/history
- Missing Files: Creates default state gracefully
- Corrupted Data: Skips invalid entries
- Write Failures: Continues operation without crashing
Journeys are stored in journeys.txt as CSV:
A,C,17.5,21-11-2025 12:30
B,E,20.0,21-11-2025 13:15
A,D,24.5,21-11-2025 14:00Fields: FromZone,ToZone,Fare,Timestamp
- Automatic: History loaded on application startup
- Incremental: New journeys appended to file
- Resilient: Continues if file is missing
The application uses a carefully chosen color palette:
| Color | Usage |
|---|---|
| 🔵 BLUE | Headings, titles |
| 🟢 GREEN | Success messages, confirmations |
| 🔴 RED | Errors, warnings |
| 🟡 YELLOW | Information, prompts |
| 🔷 CYAN | Input labels, questions |
STU-1, STU-2, STU-3... // Students
SNR-1, SNR-2, SNR-3... // Seniors
REG-1, REG-2, REG-3... // RegularCounter increments globally across all pass types.
DD-MM-YYYY HH:MM
21-11-2025 12:30
Uses system time with automatic formatting.
Pass& operator+=(double amount)Allows intuitive recharge syntax:
(*pass) += 100; // Add ₹100 to pass-
Create Pass with Invalid Age
- Input: Text instead of number
- Expected: Error message + return to menu
-
Journey with Insufficient Balance
- Setup: Pass with ₹5, journey costs ₹45
- Expected: Transaction rejected with balance info
-
Invalid Zone Entry
- Input: Zone "Z"
- Expected: "Invalid zone! Please enter A-E."
-
Same Zone Journey
- Input: From A to A
- Expected: "Start and end zones cannot be the same!"
-
Recharge Non-Existent Pass
- Input: WRONG-ID
- Expected: "Pass not found!"
- Database integration (SQLite)
- Multi-currency support
- Monthly pass options
- Journey analytics and statistics
- GUI version (Qt/GTK)
- Online payment integration
- QR code generation for passes
- Mobile app companion
- Real-time fare updates
- Multi-language support
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Use consistent indentation (4 spaces)
- Add comments for complex logic
- Follow existing naming conventions
- Test thoroughly before submitting
This project is licensed under the MIT License - see below for details:
MIT License
Copyright (c) 2025 Lalith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Lalith
- GitHub: @LalithSecondary
- Email: [email protected]
- ANSI color codes for terminal beautification
- C++ Standard Library for robust data structures
- Open-source community for inspiration
If you encounter any issues or have questions:
- Check the Error Handling section
- Review Usage examples
- Open an issue on GitHub
- Contact the maintainer
⭐ If you found this project helpful, please consider giving it a star!
Made with ❤️ and C++