A beginner-friendly C++ OOP project demonstrating core object-oriented programming concepts
This is a terminal-based airline reservation system built in pure standard C++ to demonstrate fundamental Object-Oriented Programming (OOP) concepts. The system allows users to view flights, search by route, book seats, cancel bookings, view tickets, and see passenger manifests.
The project is designed for learning purposes with:
- Every line of code commented for educational clarity
- Beginner-friendly syntax with no complex expressions
- Pure C++ only - no external libraries or frameworks
- Fixed-size arrays instead of STL containers
- No dynamic memory allocation (no
new/delete)
Use the standard g++ compiler with this simple command:
g++ main.cpp -o airlineRequirements:
- g++ compiler (any standard version)
- No external libraries needed
- Works on Linux, macOS, and Windows (with MinGW)
After compiling, run the program:
./airlineOn Windows:
airline.exeThe project consists of exactly 4 source files plus 1 data file:
- main.cpp - Entry point containing only the main() function and includes
- classes.h - All 13 classes plus 8 exception classes
- helpers.h - All helper functions with exception handling
- README.md - This documentation file
- airline_data.txt - Auto-generated data file (created on first exit)
This project demonstrates all major OOP concepts required for an intermediate-level C++ course:
- 13 classes representing real-world entities
- Objects created and used throughout the program
- All data members are private
- Public getter and setter methods for controlled access
- Implementation details hidden from outside code
- Default constructors (no parameters)
- Parameterized constructors (with initialization values)
- Every class demonstrates constructor overloading
- Implemented in
PassengerandFlightclasses - Creates deep copies of objects safely
Flightcontains arrays ofSeat[]andBooking[]Airlinecontains array ofFlight[]- Demonstrates composition relationships
Booking::bookingCounter- shared counter for generating unique PNR numbersAirline::totalAirlinesCreated- tracks total airline objects created- Static member functions to access static data
Admininherits fromUser(User → Admin)Customerinherits fromUser(User → Customer)CashPaymentinherits fromPayment(Payment → CashPayment)LoyaltyPaymentinherits fromPayment(Payment → LoyaltyPayment)
Payment→OnlinePayment→CreditCardPayment- Three-level inheritance chain demonstrating hierarchical relationships
Userbase class uses protected members- Accessible in derived classes (
Admin,Customer) - Not accessible from outside the class hierarchy
- Virtual functions in base classes
- Overridden methods in derived classes
- Runtime polymorphism demonstrated in OOP demo menus
Bookingclass overloads the==operator- Allows comparing two bookings by their PNR number
showLoyaltyPointsUsed()is a friend ofLoyaltyPayment- Accesses private
pointsUsedmember directly - Demonstrates controlled access to private data
- Complex operations hidden inside class methods
- Simple public interfaces for users of the classes
FlightHAS-ASeat[]array (composition)FlightHAS-ABooking[]array (composition)AirlineHAS-AFlight[]array (composition)BookingHAS-APassengerobject (composition)
- Custom exception class hierarchy (AirlineException base class)
- 7 derived exception classes for specific error types
- Try-catch blocks protecting all critical operations
- Graceful error handling with clear user messages
- Data persistence using fstream (file input/output)
- Saves all flight, seat, and booking data to text file
- Loads data on program startup
- Booking counter persists across program runs
- Graceful fallback to sample data if file missing
The system contains 13 main classes plus 8 exception classes:
- Passenger - Stores passenger information (name, age, ID)
- Seat - Represents one seat on a flight (number, class, availability, price)
- Booking - Stores one reservation (PNR, passenger, seat, payment)
- Flight - Represents one flight with seats and bookings
- Airline - Manages multiple flights
- User - Base class for all system users
- Admin - Inherits from User, represents admin users
- Customer - Inherits from User, represents customer users
- Payment - Base class for all payment methods
- OnlinePayment - Inherits from Payment, base for online payments
- CreditCardPayment - Inherits from OnlinePayment (multi-level)
- CashPayment - Inherits from Payment, handles cash transactions
- LoyaltyPayment - Inherits from Payment, handles points redemption
- AirlineException - Base exception class for all errors
- InputException - Invalid user input errors
- FlightNotFoundException - Flight not found errors
- SeatUnavailableException - No seats available errors
- BookingNotFoundException - Booking/PNR not found errors
- ArrayFullException - Array capacity reached errors
- FileIOException - File read/write errors
- PaymentException - Payment validation/processing errors
- View All Flights - Display all available flights with details
- Search Flights by Route - Find flights from origin to destination
- Book a Seat - Complete booking process with payment
- Cancel a Booking - Cancel using PNR number
- View Booking Details - Display formatted boarding pass ticket
- View Passenger Manifest - Show all passengers on a flight
- Credit Card Payment (demonstrates multi-level inheritance)
- Cash Payment (with change calculation)
- Loyalty Points Payment (with friend function demonstration)
- Auto-save on Exit - All data saved to airline_data.txt
- Auto-load on Startup - Previous session data restored
- Persistent PNR Numbers - Booking counter never resets
- Graceful Fallback - Loads sample data if file missing
- Input Validation - All user inputs protected with exceptions
- Error Recovery - Program never crashes on bad input
- Clear Error Messages - Every error displays helpful message
- File Error Handling - Graceful handling of file I/O errors
- View User Profiles - Display sample admin and customer account information
- View Payment Options - Demonstration of different payment processing methods
The system loads 3 sample flights on startup:
- PK-301: Lahore → Karachi (2026-06-01, 10:00-12:00, 18 seats)
- PK-502: Islamabad → Dubai (2026-06-05, 14:00-17:30, 18 seats)
- PK-786: Karachi → London (2026-06-10, 22:00-06:00, 18 seats)
Each flight has:
- 14 Economy seats (Rs. 5,000 each)
- 4 Business seats (Rs. 12,000 each)
==========================================
AIRLINE RESERVATION SYSTEM
==========================================
1. View All Flights
2. Search Flights by Route
3. Book a Seat
4. Cancel a Booking
5. View Booking Details (Ticket)
6. View Passenger Manifest
7. Demo: User Hierarchy (OOP)
8. Demo: Payment Methods (OOP)
0. Exit
==========================================
Enter your choice : 3
==========================================
BOOK A SEAT
==========================================
Enter flight number (e.g. PK-301) : PK-301
Enter passenger full name : Ali Ahmed
Enter passenger age : 28
Enter passenger ID / Passport : PK-1234567
Enter seat class (economy / business) : economy
Payment Method:
1. Credit Card
2. Cash
3. Loyalty Points
Enter your choice (1-3) : 2
Cash payment of Rs.5000 received.
Change returned: Rs.500.
==========================================
BOOKING CONFIRMED
==========================================
PNR Number : PNR001
Seat Number : 1
Seat Class : Economy
Amount Paid : Rs.5000
SAVE YOUR PNR NUMBER FOR FUTURE USE!
==========================================
This project follows strict coding standards for educational purposes:
✅ Every line has a comment explaining what it does
✅ No abbreviations - all variable names are full English words
✅ No pointers except where absolutely necessary
✅ No dynamic memory - all objects on the stack
✅ Fixed array sizes defined as constants
✅ Input validation on all user inputs
✅ Clean terminal output with separators and formatting
✅ Beginner-friendly syntax - no complex expressions
After studying this project, you will understand:
- How to design classes for real-world entities
- How to implement encapsulation with private data and public methods
- How to use inheritance to create class hierarchies
- How to implement polymorphism with virtual functions
- How to overload operators for custom behavior
- How to use friend functions for controlled access
- How to manage relationships between classes (composition)
- How to use static members for class-level data
- How to implement exception handling with custom exception classes
- How to implement file I/O for data persistence
- How to write clean, commented, beginner-friendly code
This project intentionally follows these constraints for educational purposes:
- Only 4 headers allowed:
<iostream>,<string>,<cstring>,<fstream> - No STL containers: No vectors, maps, lists, etc.
- No dynamic memory: No
newordeletekeywords - Fixed arrays only: All collections use plain C++ arrays
- No external libraries: Pure standard C++ only
- Exactly 4 source files: main.cpp, classes.h, helpers.h, README.md
- 1 data file: airline_data.txt (auto-generated)
OOP Project - Airline Reservation System
Created for educational purposes to demonstrate C++ OOP concepts
Date: 2026-05-05
This is an educational project. Feel free to use it for learning purposes.
End of README