From c8cd9e2b056cc996e1b3296d7e0202824a5073d9 Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sat, 26 Apr 2025 00:35:07 +0530 Subject: [PATCH 1/8] updated agent --- agentNode.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/agentNode.cpp b/agentNode.cpp index ef9bbf5..f60a88c 100644 --- a/agentNode.cpp +++ b/agentNode.cpp @@ -1,12 +1,26 @@ #include using namespace std; class Agent{ - private: - int ID; - node* next; public: + int ID; + bool isAvailable; Agent(int id){ ID = id; - next = NULL; + isAvailable = true; } -}; \ No newline at end of file +}; + +void releaseAgent(vector& agents, int agentId) { + for (auto& agent : agents) { + if (agent.ID == agentId) { + if (!agent.isAvailable) { + agent.isAvailable = true; + cout << "Agent " << agent.ID << " is now available.\n"; + } else { + cout << "Agent " << agent.ID << " is already available.\n"; + } + return; + } + } + cout << "Agent ID not found.\n"; +} From 14b12c1033aaadd405c44b074b57b20cba2b6a2d Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sat, 26 Apr 2025 00:35:31 +0530 Subject: [PATCH 2/8] updated main --- main.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 4e75e8c..870d96a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,47 @@ -#include -using namespace std; -int main(){ - cout<<"DS project"<> numAgents; + + vector agents; + for (int i = 1; i <= numAgents; ++i) { + agents.push_back(Agent(i)); + } + + while (true) { + cout << "\n--- Chat Queue Menu ---\n"; + cout << "1. New user joins\n"; + cout << "2. Serve next user\n"; + cout << "3. Release agent\n"; + cout << "4. Show queue\n"; + cout << "5. Exit\n"; + cout << "Enter choice: "; + cin >> choice; + + switch (choice) { + case 1: + chatQueue.joinQueue(Id++); + break; + case 2: + chatQueue.serveCompleted(agents); + break; + case 3: { + int Id; + cout << "Enter Agent ID to release: "; + cin >> Id; + releaseAgent(agents, Id); + break; + } + case 4: + chatQueue.showQueue(); + break; + case 5: + return 0; + default: + cout << "Invalid choice.\n"; + } + } +} From 84fb85e7e825ba9dd1713d9db5edb7a47f671ecc Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sat, 26 Apr 2025 00:35:46 +0530 Subject: [PATCH 3/8] updated queue --- QueueClass.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 QueueClass.cpp diff --git a/QueueClass.cpp b/QueueClass.cpp new file mode 100644 index 0000000..fe6dbb7 --- /dev/null +++ b/QueueClass.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; +class Queue { + private: + node* front; + node* rear; + + public: + Queue() { + front = NULL; + rear = NULL; + } + void joinQueue(int Id); + void serveCompleted(vector& agents); + void showQueue(); + }; + void Queue::joinQueue(int Id) { + node* newUser = new node(Id); + if (rear == NULL) { + front = rear = newUser; + } else { + rear->next = newUser; + rear = newUser; + } + cout << "User " << Id << " joined the queue.\n"; + } + void Queue::serveCompleted(vector& agents) { + if (front == NULL) { + cout << "No users in queue.\n"; + return; + } + for (auto& agent : agents) { + if (agent.isAvailable) { + node* temp = front; + front = front->next; + if (front == NULL) rear = NULL; + + agent.isAvailable = false; + + cout << "Agent " << agent.ID << " is now serving User " << temp->userID << "\n"; + delete temp; + return; + } + } + cout << "No available agents at the moment. Please wait.\n"; + } + + void Queue::showQueue() { + if (front == NULL) { + cout << "Queue is empty.\n"; + return; + } + + cout << "Current Queue: "; + node* temp = front; + while (temp != NULL) { + cout << temp->userID << " "; + temp = temp->next; + } + cout << "\n"; + } + \ No newline at end of file From c471907b06e275db7f82240778095993cb595af0 Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sat, 26 Apr 2025 00:36:07 +0530 Subject: [PATCH 4/8] updated node --- queueNode.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/queueNode.cpp b/queueNode.cpp index 7941b48..b5e1aa3 100644 --- a/queueNode.cpp +++ b/queueNode.cpp @@ -2,12 +2,11 @@ #include using namespace std; class node{ - private: - string userName; - node* next; public: - node(string name){ - userName = name; + int userID; + node* next; + node(int id){ + userID = id; next = NULL; } -} \ No newline at end of file +}; \ No newline at end of file From 59d0129fc1af361d4542b80325345e896b2774ec Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sat, 26 Apr 2025 20:40:39 +0530 Subject: [PATCH 5/8] fourth day --- text2.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/text2.txt b/text2.txt index a66990d..7144756 100644 --- a/text2.txt +++ b/text2.txt @@ -1,3 +1,4 @@ second day of ds project agent node created -third day working on project \ No newline at end of file +third day working on project +fourth day \ No newline at end of file From 645714449822e34e650b8ed4590ce54e4acba61c Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sun, 27 Apr 2025 21:13:40 +0530 Subject: [PATCH 6/8] code --- code.cpp | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 code.cpp diff --git a/code.cpp b/code.cpp new file mode 100644 index 0000000..434c21b --- /dev/null +++ b/code.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +using namespace std; +class node{ + public: + int userID; + node* next; + node(int id){ + userID = id; + next = NULL; + } +}; +class Agent{ + public: + int ID; + bool isAvailable; + Agent(int id){ + ID = id; + isAvailable = true; + } +}; + + + +class Queue { + private: + node* front; + node* rear; + + public: + Queue() { + front = nullptr; + rear = nullptr; + } + void joinQueue(int Id); + void serveCompleted(vector& agents); + void showQueue(); + }; + void Queue::joinQueue(int Id) { + node* newUser = new node(Id); + if (rear == nullptr) { + front = rear = newUser; + } else { + rear->next = newUser; + rear = newUser; + } + cout << "User " << Id << " joined the queue.\n"; + } + void Queue::serveCompleted(vector& agents) { + if (front == NULL) { + std::cout << "No users in queue.\n"; + return; + } + for (auto& agent : agents) { + if (agent.isAvailable) { + node* temp = front; + front = front->next; + if (front == NULL) rear = NULL; + + agent.isAvailable = false; + + cout << "Agent " << agent.ID<< " is now serving User " << temp->userID << "\n"; + delete temp; + return; + } + } + cout << "No available agents at the moment. Please wait.\n"; + } + + void Queue::showQueue() { + if (front == NULL) { + cout << "Queue is empty.\n"; + return; + } + + cout << "Current Queue: "; + node* temp = front; + while (temp != nullptr) { + cout << temp->userID << " "; + temp = temp->next; + } + cout << "\n"; + } + + + + +void releaseAgent(vector& agents, int agentId) { + for (auto& agent : agents) { + if (agent.ID == agentId) { + if (!agent.isAvailable) { + agent.isAvailable = true; + cout << "Agent " << agent.ID<< " is now available.\n"; + } else { + cout << "Agent " << agent.ID << " is already available.\n"; + } + return; + } + } + cout << "Agent ID not found.\n"; +} + + + +int main() { + Queue chatQueue; + int choice, Id = 1; + int numAgents; + + cout << "Enter number of agents: "; + cin >> numAgents; + + vector agents; + for (int i = 1; i <= numAgents; ++i) { + agents.push_back(Agent(i)); + } + + while (true) { + cout << "\n--- Chat Queue Menu ---\n"; + cout << "1. New user joins\n"; + cout << "2. Serve next user\n"; + cout << "3. Release agent\n"; + cout << "4. Show queue\n"; + cout << "5. Exit\n"; + cout << "Enter choice: "; + cin >> choice; + + switch (choice) { + case 1: + chatQueue.joinQueue(Id++); + break; + case 2: + chatQueue.serveCompleted(agents); + break; + case 3: { + int Id; + cout << "Enter Agent ID to release: "; + cin >> Id; + releaseAgent(agents, Id); + break; + } + case 4: + chatQueue.showQueue(); + break; + case 5: + return 0; + default: + std::cout << "Invalid choice.\n"; + } + } +} \ No newline at end of file From 7d1281442337b8eb5689a5db868b483920170c99 Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sun, 27 Apr 2025 21:16:02 +0530 Subject: [PATCH 7/8] fifth --- text2.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/text2.txt b/text2.txt index 7144756..65855dd 100644 --- a/text2.txt +++ b/text2.txt @@ -1,4 +1,5 @@ second day of ds project agent node created third day working on project -fourth day \ No newline at end of file +fourth day +fifth day \ No newline at end of file From f16f49b74f97878df0ba61731e04e0dcec29c908 Mon Sep 17 00:00:00 2001 From: rashmith321 Date: Sun, 27 Apr 2025 21:18:47 +0530 Subject: [PATCH 8/8] 5th --- text2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text2.txt b/text2.txt index 65855dd..0734bc8 100644 --- a/text2.txt +++ b/text2.txt @@ -2,4 +2,4 @@ second day of ds project agent node created third day working on project fourth day -fifth day \ No newline at end of file +fifth day yestarday commit not completed \ No newline at end of file