-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent_manager.h
82 lines (73 loc) · 1.96 KB
/
agent_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef AGENT_MANAGER_H
#define AGENT_MANAGER_H
#include "agent.h"
#include <iostream>
using namespace std;
class AgentManager
{
private:
Agent **agents;
int agentCount;
int capacity;
// mathod to expand the capacity to store new registered agents
void expandCapacity()
{
int newCapacity = capacity * 2;
Agent **newAgents = new Agent *[newCapacity];
for (int i = 0; i < agentCount; i++)
{
newAgents[i] = agents[i];
}
delete[] agents;
agents = newAgents;
capacity = newCapacity;
}
public:
AgentManager(int initialCapacity = 10) : agentCount(0), capacity(initialCapacity)
{
agents = new Agent *[capacity];
}
~AgentManager()
{
for (int i = 0; i < agentCount; i++)
{
delete agents[i];
}
delete[] agents;
}
// method to add new agent
bool addAgent(int id, const string &name)
{
if (agentCount == capacity)
{
expandCapacity();
}
agents[agentCount++] = new Agent(id, name);
return true;
}
// methods to assign tickets to the agent
bool assignTicketToAgent(int ticketID)
{
for (int i = 0; i < agentCount; i++)
{
if (agents[i]->isAvailable && agents[i]->assignTicket(ticketID))
{
cout << "Assigned Ticket ID \"" << ticketID << "\" to Agent \"" << agents[i]->name << "\" with Agent ID \"" << agents[i]->id << "\"\n";
return true;
}
}
cout << "No available agents to assign\n";
return false;
}
// method to Display all the current agents
void displayAllAgents() const
{
cout << "----------------\n";
for (int i = 0; i < agentCount; i++)
{
agents[i]->displayAssignedTickets();
}
cout << "--------------------------------------------------------------\n";
}
};
#endif