Untitled

 avatar
unknown
plain_text
5 months ago
6.8 kB
2
Indexable
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int id = 0;

struct Node {
    int id;
    string name;
    string phone;
    string gender;
    string job;
    string registration;

    Node(const int clientID, const string& clientName, const string& clientPhone,
         const string& clientGender, const string& clientJob, const string& clientRegistration) {
        id = clientID;
        name = clientName;
        phone = clientPhone;
        gender = clientGender;
        job = clientJob;
        registration = clientRegistration;
    }
};

struct Queue {
    vector<Node> Clients;

    void enqueue(const string& clientName, const string& clientPhone, const string& clientGender,
                 const string& clientJob, const string& clientRegistration) {
        Clients.emplace_back(id++, clientName, clientPhone, clientGender, clientJob, clientRegistration);
    }

    void dequeue() {
        if (Clients.empty()) {
            cerr << "Error: Queue is empty" << endl;
            return;
        }
        Clients.erase(Clients.begin());
    }

    void printAllClients() {
        for (const auto& client : Clients) {
            cout << "ID: " << client.id << ", Name: " << client.name << ", Phone: " << client.phone
                 << ", Gender: " << client.gender << ", Job: " << client.job
                 << ", Registration: " << client.registration << endl;
        }
    }

    void printVIPClients() {
        for (const auto& client : Clients) {
            if (client.registration == "VIP") {
                cout << "ID: " << client.id << ", Name: " << client.name << ", Phone: " << client.phone
                     << ", Gender: " << client.gender << ", Job: " << client.job << endl;
            }
        }
    }

    void printNormalClients() {
        for (const auto& client : Clients) {
            if (client.registration == "Normal") {
                cout << "ID: " << client.id << ", Name: " << client.name << ", Phone: " << client.phone
                     << ", Gender: " << client.gender << ", Job: " << client.job << endl;
            }
        }
    }

    bool Search(int ID) {
        for (const auto& client : Clients) {
            if (client.id == ID) {
                cout << "ID: " << client.id << ", Name: " << client.name << ", Phone: " << client.phone
                     << ", Gender: " << client.gender << ", Job: " << client.job
                     << ", Registration: " << client.registration << endl;
                return true;
            }
        }
        return false;
    }

    void update(int ID, const string& newName, const string& newPhone, const string& newRegistration, const string& newJob) {
        for (auto& client : Clients) {
            if (client.id == ID) {
                client.name = newName;
                client.phone = newPhone;
                client.registration = newRegistration;
                client.job = newJob;
                return;
            }
        }
        cerr << "Error: Client ID not found for update" << endl;
    }

    void deleteClient(int ID) {
        auto it = find_if(Clients.begin(), Clients.end(), [ID](const Node& client) {
            return client.id == ID;
        });
        if (it != Clients.end()) {
            Clients.erase(it);
            cout << "Client with ID: " << ID << " has been deleted" << endl;
        } else {
            cerr << "Error: Client ID not found for deletion" << endl;
        }
    }

    void display() {
        for (const auto& client : Clients) {
            cout << "ID: " << client.id << ", Name: " << client.name << ", Phone: " << client.phone
                 << ", Gender: " << client.gender << ", Job: " << client.job
                 << ", Registration: " << client.registration << endl;
        }
    }

    bool isEmpty() {
        return Clients.empty();
    }
};

int main() {
    Queue clients;
    cout << "**********************************************"
            "**********************************";
    cout << "\n\n\t\t\t\tManagement System";
    cout << "\n\n\t\t\t\t Control Panel\n";
    cout << "**********************************************"
            "**********************************\n";
    while (true) {
        cout << "\n 1. Enqueue";
        cout << "\n 2. Dequeue";
        cout << "\n 3. Print All Clients";
        cout << "\n 4. Print VIP Clients";
        cout << "\n 5. Print Normal Clients";
        cout << "\n 6. Search";
        cout << "\n 7. Update";
        cout << "\n 8. Delete";
        cout << "\n 9. Exit" << endl;
        cout << "Enter your choice:" << endl;
        int choice;
        cin >> choice;
        if (choice == 1) {
            string name, phone, gender, job, registration;
            cout << "Enter your name: " << endl;
            cin.ignore();
            getline(cin, name);
            cout << "Enter your phone number: " << endl;
            cin >> phone;
            cout << "Enter your gender: " << endl;
            cin >> gender;
            cout << "Enter your job: " << endl;
            cin.ignore();
            getline(cin, job);
            cout << "Enter your registration [VIP OR NORMAL]: " << endl;
            cin >> registration;
            clients.enqueue(name, phone, gender, job, registration);
        } else if (choice == 2) {
            clients.dequeue();
        } else if (choice == 3) {
            clients.printAllClients();
        } else if (choice == 4) {
            clients.printVIPClients();
        } else if (choice == 5) {
            clients.printNormalClients();
        } else if (choice == 6) {
            cout << "Enter client ID" << endl;
            int id;
            cin >> id;
            if (!clients.Search(id)) {
                cout << "Not Found" << endl;
            }
        } else if (choice == 7) {
            cout << "Enter client ID" << endl;
            int id;
            cin >> id;
            string name, phone, job, registration;
            cout << "Enter your new name: " << endl;
            cin.ignore();
            getline(cin, name);
            cout << "Enter your phone: " << endl;
            cin >> phone;
            cout << "Enter your job: " << endl;
            cin.ignore();
            getline(cin, job);
            cout << "Enter your new registration: " << endl;
            cin >> registration;
            clients.update(id, name, phone, registration, job);
        } else if (choice == 8) {
            cout << "Enter client ID" << endl;
            int id;
            cin >> id;
            clients.deleteClient(id);
        } else {
            return 0;
        }
    }
}
Editor is loading...
Leave a Comment