All Projects

Bus Ticket Booking System in Python
Bus Ticket Booking System in Java
Bus Ticket Booking System in Cpp
Bus Ticket Booking System in C
Cafe Order System in Python
Cafe Order System in Java
Cafe Order System in Cpp
Cafe Order System in C
Social Media Account Details Manager in Python
Social Media Account Details Manager in Java
Social Media Account Details Manager in Cpp
Social Media Account Details Manager in C
Mini ATM in Python Language
Mini ATM in Java Language
Mini ATM in cpp language
Mini ATM in c language
Pocket Money Manager in Python Language
Pocket Money Manager in Java Language
Pocket Money Manager in Cpp Language
Pocket Money Manager in C Language
Username Password Generator in Python Language
Username Password Generator in Cpp Language
Username Password Generator in C Language
Telephone Directory in Python Language
Telephone Directory in Java Language
Telephone Directory in Cpp Language
Telephone Directory in C Language
Calander in Cpp Language
Calander in C Language
NoteBook in Python Language
NoteBook in Cpp Language
NoteBook in C Language
Voting System in Python Language
Voting System in Java Language
Voting System in Cpp Language
Voting System in C Language
Age Calculator in Python Language
Age Calculator in Java Language
Age Calculator in Cpp Language
Age Calculator in C Language
Currency Converter in Python Language
Currency Converter in Java Language
Currency Converter in Cpp Language
Currency Converter in C Language
Random Password Generator in python language
Random Password Generator in java language
Random Password Generator in cpp language
Random Password Generator in c language
Billing System in python language
Billing System in c++ language
Billing System in c language
Atm in c language

Bus Ticket Booking System in Cpp


Aniket The Programmer

1K+ Subscribers

Click To Subscribe My Channel

Subscribe

Source Code

        
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Booking {
public:
    string name;
    int seatNo;
    // Add more fields as needed

    Booking(string _name, int _seatNo) : name(_name), seatNo(_seatNo) {
        // Initialize other fields as needed
    }
};

class BusBookingSystem {
private:
    vector<Booking> bookings;

public:
    void bookSeat() {
        string name;
        int seatNo;

        cout << "Enter name: ";
        cin >> name;

        cout << "Enter seat number: ";
        cin >> seatNo;

        // Add more input fields as needed

        Booking newBooking(name, seatNo);
        bookings.push_back(newBooking);
        cout << "Seat booked successfully.\n";
    }

    void viewReservations() {
        if (bookings.empty()) {
            cout << "No reservations made yet.\n";
            return;
        }

        cout << "All reservations:\n";
        cout << "Seat No.\tName\n";
        for (const auto& booking : bookings) {
            cout << booking.seatNo << "\t\t" << booking.name << endl;
        }
    }

    void editReservation() {
        int seatToEdit;
        cout << "Enter seat number to edit: ";
        cin >> seatToEdit;

        bool found = false;
        for (auto& booking : bookings) {
            if (booking.seatNo == seatToEdit) {
                cout << "Enter new name: ";
                cin >> booking.name;
                // Add more fields to edit as needed

                cout << "Reservation edited successfully.\n";
                found = true;
                break;
            }
        }

        if (!found) {
            cout << "Reservation not found.\n";
        }
    }

    void printTicket() {
        int seatToPrint;
        cout << "Enter seat number to print ticket: ";
        cin >> seatToPrint;

        bool found = false;
        for (const auto& booking : bookings) {
            if (booking.seatNo == seatToPrint) {
                cout << "Ticket for Seat No. " << booking.seatNo << endl;
                cout << "Passenger Name: " << booking.name << endl;
                // Add more fields to print as needed

                found = true;
                break;
            }
        }

        if (!found) {
            cout << "Reservation not found.\n";
        }
    }
};

int main() {
    BusBookingSystem system;
    int choice;

    do {
        cout << "\nMini Bus Booking System\n";
        cout << "1. Book a seat\n";
        cout << "2. View reservations\n";
        cout << "3. Edit a reservation\n";
        cout << "4. Print a ticket\n";
        cout << "5. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
            case 1:
                system.bookSeat();
                break;
            case 2:
                system.viewReservations();
                break;
            case 3:
                system.editReservation();
                break;
            case 4:
                system.printTicket();
                break;
            case 5:
                cout << "Exiting...\n";
                break;
            default:
                cout << "Invalid choice. Please enter a valid option.\n";
        }
    } while (choice != 5);

    return 0;
}
        
    

Source Code Github Link: View

View Video On Youtube Link: View