#include <iostream>

#include <string>


using namespace std;


class Ticket {

protected:

    int ticketID;

    string passengerName;

    string trainName;

    double fare;

    string ticketStatus;


public:

    Ticket(int id, string name, string train, double cost)

        : ticketID(id), passengerName(name), trainName(train), fare(cost), ticketStatus("Pending") {}


    int getTicketID() const {

        return ticketID;

    }


    double getFare() const {

        return fare;

    }


    virtual void displayDetails() {

        cout << "Ticket ID: " << ticketID << endl;

        cout << "Passenger: " << passengerName << endl;

        cout << "Train: " << trainName << endl;

        cout << "Fare: " << fare << endl;

        cout << "Ticket Status: " << ticketStatus << endl;

    }


    virtual void updateTicketStatus(string status) {

        ticketStatus = status;

    }


    virtual ~Ticket() {}

};


class TicketManagementSystem {

private:

    static const int MAX_TICKETS = 100;

    Ticket* tickets[MAX_TICKETS];

    int numTickets;


public:

    TicketManagementSystem() : numTickets(0) {}


    void addTicket(Ticket* ticket) {

        if (numTickets < MAX_TICKETS) {

            tickets[numTickets++] = ticket;

            cout << "Ticket added successfully." << endl;

        } else {

            cout << "Ticket limit reached. Cannot add more tickets." << endl;

        }

    }


    void displayTickets() {

        for (int i = 0; i < numTickets; i++) {

            tickets[i]->displayDetails();

            cout << endl;

        }

    }


    void updateTicketStatus(int ticketID, string newStatus) {

        for (int i = 0; i < numTickets; i++) {

            if (tickets[i]->getTicketID() == ticketID) {

                tickets[i]->updateTicketStatus(newStatus);

                cout << "Ticket status updated successfully." << endl;

                return;

            }

        }

        cout << "Ticket not found." << endl;

    }


    void deleteTicket(int ticketID) {

        for (int i = 0; i < numTickets; i++) {

            if (tickets[i]->getTicketID() == ticketID) {

                delete tickets[i];

                tickets[i] = tickets[numTickets - 1];

                numTickets--;

                cout << "Ticket deleted successfully." << endl;

                return;

            }

        }

        cout << "Ticket not found." << endl;

    }


    void searchTicketByID(int ticketID) {

        for (int i = 0; i < numTickets; i++) {

            if (tickets[i]->getTicketID() == ticketID) {

                tickets[i]->displayDetails();

                return;

            }

        }

        cout << "Ticket not found." << endl;

    }


    void generateReports() {

        double totalRevenue = 0.0;


        cout << "Ticket Reports" << endl;

        cout << "==============" << endl;


        for (int i = 0; i < numTickets; i++) {

            totalRevenue += tickets[i]->getFare();

        }


        cout << "Total Number of Tickets: " << numTickets << endl;

        cout << "Total Revenue: " << totalRevenue << endl;

    }


    ~TicketManagementSystem() {

        for (int i = 0; i < numTickets; i++) {

            delete tickets[i];

        }

    }

};


class PremiumTicket : public Ticket {

private:

    string additionalService;


public:

    PremiumTicket(int id, string name, string train, double cost, string service)

        : Ticket(id, name, train, cost), additionalService(service) {}


    void displayDetails() override {

        Ticket::displayDetails();

        cout << "Additional Service: " << additionalService << endl;

    }

};


int main() {

    TicketManagementSystem system;


    while (true) {

        cout << "Ticket Management System" << endl;

        cout << "1. Manage Tickets" << endl;

        cout << "2. Search Tickets" << endl;

        cout << "3. Reports of Tickets" << endl;

        cout << "4. Exit" << endl;


        int choice;

        cin >> choice;


        switch (choice) {

            case 1: {

                cout << "1. Add Tickets" << endl;

                cout << "2. Update Tickets" << endl;

                cout << "3. Display Tickets" << endl;

                cout << "4. Delete Tickets" << endl;

                cout << "5. Exit" << endl;


                int subChoice;

                cin >> subChoice;


                switch (subChoice) {

                    case 1: {

                        int id;

                        double fare;

                        string name, train;


                        cout << "Enter Ticket ID: ";

                        cin >> id;

                        cout << "Enter Passenger Name: ";

                        cin.ignore();

                        getline(cin, name);

                        cout << "Enter Train Name: ";

                        getline(cin, train);

                        cout << "Enter Fare: ";

                        cin >> fare;


                        Ticket* newTicket = new Ticket(id, name, train, fare);

                        system.addTicket(newTicket);

                        break;

                    }

                    case 2: {

                        int ticketID;

                        string newStatus;

                        cout << "Enter Ticket ID: ";

                        cin >> ticketID;

                        cout << "Enter new status: ";

                        cin.ignore();

                        getline(cin, newStatus);

                        system.updateTicketStatus(ticketID, newStatus);

                        break;

                    }

                    case 3: {

                        system.displayTickets();

                        break;

                    }

                    case 4: {

                        int ticketID;

                        cout << "Enter Ticket ID to delete: ";

                        cin >> ticketID;

                        system.deleteTicket(ticketID);

                        break;

                    }

                    case 5:

                        cout << "Returning to the main menu." << endl;

                        break;

                    default:

                        cout << "Invalid choice. Please select a valid option." << endl;

                }

                break;

            }

            case 2: {

                int ticketID;

                cout << "Enter Ticket ID to search: ";

                cin >> ticketID;

                system.searchTicketByID(ticketID);

                break;

            }

            case 3: {

                system.generateReports();

                break;

            }

            case 4:

                cout << "Exiting..." << endl;

                return 0;

            default:

                cout << "Invalid choice. Please select a valid option." << endl;

        }

    }


    return 0;

}