This project is a simplified IRCTC Railway Reservation System implemented in modern C++17, following Object-Oriented Analysis & Design principles, SOLID principles, and classic design patterns.
include/β Header files for all domain entities and services:User.h,Admin.h,Train.h,Ticket.hPayment.h,UpiPayment.h,CardPayment.h,NetBankingPayment.hPaymentFactory.h,TrainDatabase.h,TrainService.hPaymentService.h,BookingService.hFareStrategy.h,SimpleFareStrategy.h
src/β Implementation files for all headers.main.cppβ Interactive demo program:- Prompts for user details
- Seeds sample trains
- Lets the user search trains
- Books a ticket based on user choice
- Processes payment
- Optionally cancels the ticket and shows updated status
Makefileβ Build script (maketo build,./irctcto run). //uml/β UML design diagrams (no longer included in this repository).
- Actors: User, Admin, Payment Gateway (Use Case / Sequence diagrams).
- Entities:
User,Admin,Train,Ticket.
- Payments:
- Interface:
Payment - Implementations:
UpiPayment,CardPayment,NetBankingPayment - Factory:
PaymentFactory
- Interface:
- Core Services:
TrainDatabase(Singleton in-memory store forTrain)TrainService(search, check availability, seat management)PaymentService(delegates toPaymentFactoryandPayment)BookingService(coordinates booking, payment, ticket creation)
- Strategy:
FareStrategy(interface),SimpleFareStrategy(concrete)
- Relationships:
BookingServiceusesTrainService+PaymentService+FareStrategy.PaymentServiceusesPaymentFactoryβPayment(interface).TrainDatabasestoresTrainobjects (Singleton).Ticketdepends onTrain+User.
All these relationships are reflected in the original UML design diagrams.
- S β Single Responsibility
Trainonly manages its own seat and schedule data.TrainDatabaseonly manages storage/retrieval of trains.TrainServicehandles train-related use cases.BookingServiceorchestrates booking and cancellation workflows.PaymentServiceorchestrates payment usingPaymentabstractions.
- O β Open/Closed
- New payment types can be added by creating a new class implementing
Paymentand registering a creator inPaymentFactory, without changing callers ofPaymentService. - New fare calculation strategies can be added by implementing
FareStrategyand injecting intoBookingService.
- New payment types can be added by creating a new class implementing
- L β Liskov Substitution
UpiPayment,CardPayment,NetBankingPaymentcan all be used whereverPayment*/Payment&is expected.
- I β Interface Segregation
Paymentis focused only on payment operations.FareStrategyis focused only on fare calculation.
- D β Dependency Inversion
- High-level
BookingServicedepends on abstractions (FareStrategy,PaymentthroughPaymentServiceandPaymentFactory), not on concrete payment types. PaymentServicedepends onPaymentFactoryandPaymentabstraction, not on specific payment implementations.
- High-level
- Singleton Pattern β
TrainDatabase- Provides a single shared in-memory store for all train objects.
- Factory Pattern β
PaymentFactory- Centralizes creation of payment method objects (
Paymentimplementations).
- Centralizes creation of payment method objects (
- Strategy Pattern β
FareStrategy/SimpleFareStrategy- Encapsulates fare calculation logic, allowing future strategies (e.g., dynamic pricing, discounts).
cd IRCTC
make
./irctc # on Linux / macOS
# or .\irctc.exe on WindowsWhen you run the program you will see an interactive menu that lets you:
- Enter user details.
- Search trains by source and destination.
- Select a train, number of seats, date, and payment method.
- View the booked ticket and optionally cancel it.