Skip to content

LalithSecondary/TransistSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚇 SmartTransit - Metro Transit System

C++ Version License

A comprehensive command-line metro transit management system with fare calculation, pass management, and journey tracking.

FeaturesInstallationUsageArchitectureDocumentation


📋 Table of Contents


🌟 Overview

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.

Why SmartTransit?

  • 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

✨ Features

🎫 Pass Management

  • 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)

🚉 Journey System

  • 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

📊 History & Tracking

  • Journey History: View all past journeys with timestamps
  • Persistent Storage: CSV-based storage in journeys.txt
  • Auto-Loading: Historical data loaded on startup

🎨 User Interface

  • 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

🏗️ System Architecture

Class Hierarchy

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

Object-Oriented Principles

  • 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

🔧 Installation

Prerequisites

  • 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)

Compilation

# 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

Compilation Flags Explained

  • -o metro: Output executable named "metro"
  • -std=c++11: Use C++11 standard features

🚀 Usage

Main Menu

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

Workflow Examples

1️⃣ Creating a Student Pass

> 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

2️⃣ Starting a Journey

> 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

3️⃣ Recharging a Pass

> 5
Enter Pass ID: STU-1
Amount: 50

✔ New Balance: 132.5

🎫 Pass Types

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

Fare Calculation Examples

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

🗺️ Zone & Fare Matrix

Zone Layout

   A ←→ B ←→ C ←→ D ←→ E

Fare Matrix (₹)

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)


📁 Code Structure

File Organization

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

Key Components

main.cpp

  • Application entry point
  • Menu-driven interface
  • Input validation and error handling
  • ANSI color initialization

TransitSystem.cpp

  • Central controller class
  • Pass creation and management
  • Journey processing
  • File I/O operations
  • Fare calculation logic

Pass.cpp

  • Abstract Pass base class
  • StudentPass, SeniorPass, RegularPass derived classes
  • Virtual fare calculation methods
  • Balance management

Journey.cpp

  • Journey data structure
  • Timestamp generation
  • CSV serialization
  • Display formatting

colors.hpp

  • ANSI escape code definitions
  • Color constants (RED, GREEN, YELLOW, BLUE, CYAN)
  • Formatting (BOLD, RESET)
  • Special symbols (TICK ✔, CROSS ✖)
  • enableANSI() function for Windows compatibility

🛡️ Error Handling

SmartTransit includes comprehensive error handling:

Input Validation

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!"

Business Logic Validation

  • 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

File Operations

  • Missing Files: Creates default state gracefully
  • Corrupted Data: Skips invalid entries
  • Write Failures: Continues operation without crashing

💾 Data Persistence

Journey Storage Format

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:00

Fields: FromZone,ToZone,Fare,Timestamp

Data Loading

  • Automatic: History loaded on application startup
  • Incremental: New journeys appended to file
  • Resilient: Continues if file is missing

🎨 Color Scheme

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

🔍 Advanced Features

ID Generation System

STU-1, STU-2, STU-3...  // Students
SNR-1, SNR-2, SNR-3...  // Seniors
REG-1, REG-2, REG-3...  // Regular

Counter increments globally across all pass types.

Timestamp Format

DD-MM-YYYY HH:MM
21-11-2025 12:30

Uses system time with automatic formatting.

Operator Overloading

Pass& operator+=(double amount)

Allows intuitive recharge syntax:

(*pass) += 100;  // Add ₹100 to pass

🧪 Testing

Manual Test Cases

  1. Create Pass with Invalid Age

    • Input: Text instead of number
    • Expected: Error message + return to menu
  2. Journey with Insufficient Balance

    • Setup: Pass with ₹5, journey costs ₹45
    • Expected: Transaction rejected with balance info
  3. Invalid Zone Entry

    • Input: Zone "Z"
    • Expected: "Invalid zone! Please enter A-E."
  4. Same Zone Journey

    • Input: From A to A
    • Expected: "Start and end zones cannot be the same!"
  5. Recharge Non-Existent Pass

    • Input: WRONG-ID
    • Expected: "Pass not found!"

🚧 Future Enhancements

  • 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

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style Guidelines

  • Use consistent indentation (4 spaces)
  • Add comments for complex logic
  • Follow existing naming conventions
  • Test thoroughly before submitting

📄 License

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.

👨‍💻 Author

Lalith


🙏 Acknowledgments

  • ANSI color codes for terminal beautification
  • C++ Standard Library for robust data structures
  • Open-source community for inspiration

📞 Support

If you encounter any issues or have questions:

  1. Check the Error Handling section
  2. Review Usage examples
  3. Open an issue on GitHub
  4. Contact the maintainer

⭐ If you found this project helpful, please consider giving it a star!

Made with ❤️ and C++

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages