forked from Yamini2391/VaccinationRegistartionSystem
-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin.h
222 lines (192 loc) · 5.6 KB
/
admin.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Members -
* 2328 - Shruti Datar
* 2329 - Samruddhi Deode
* 2332 - Nisha Deshmukh
* 2336 - Yamini Dongaonkar
*/
/*
* admin.h
*
* Created on: 06-May-2021
*
* Includes the Admin class to provide the functionalities required by an Administrator.
*/
#ifndef ADMIN_H_
#define ADMIN_H_
#include <string>
#include <ctime>
#include "citizen.h"
#include "dateutil.h"
using namespace std;
class Admin
{
string pswd;
static int available_shots; // The number of vaccine shots available per day
static string last_date; // Used by the run_process function of this class to record the date of its last execution
public:
static int age_eligibility; // The minimum age eligible for registration
Admin()
{
/*
* Constructor
*/
pswd = "vaccine";
}
bool run_process(CitizenQueueList &cqueue);
void display_top_n(CitizenQueueList &cqueue);
void display_today(CitizenQueueList &cqueue);
void change_eligibility(CitizenQueueList &cqueue);
void change_available_shots();
bool verify_password(string pass);
void remove(Citizen *user, string pswd, CitizenQueueList &cqueue);
void remove_age_ineligible(CitizenQueueList &cqueue);
friend class CitizenQueueList;
};
// ======================================================================================================
// Admin class implementation
// Static member initializations
int Admin::age_eligibility = 18;
int Admin::available_shots = 1;
string Admin::last_date = "";
bool Admin::verify_password(string pass)
{
/*
* Verifies the Admin password.
* Returns true if the password matches.
*/
return pass == pswd;
}
bool Admin::run_process(CitizenQueueList &cqueue)
{
/*
* The most important functionality of this class.
* It allocates slots to citizens in a priority queue-list.
* Returns true if the allocation process has executed.
*/
Citizen *selected = cqueue.front;
Citizen *dq = nullptr;
// Extracting today's date
time_t now = time(0);
tm *ltm = localtime(&now);
int day = ltm->tm_mday;
int month = ltm->tm_mon + 1;
int year = ltm->tm_year + 1900;
/*
* This code has to be uncommented to generate full output, as
* otherwise, the program will have to remain running over several days
* to demonstrate the full functionality, due to use of <ctime>
*/
/*
cout << "Enter day :";
cin >> day;
cout << "Enter month :";
cin >> month;
cout << "Enter year :";
cin >> year;
*/
string today = date_string(day, month, year); // The representation of a today's date as a string
if (today == last_date) // This prevents multiple allotment rounds on the same day.
return false;
// ALLOTMENT PROCESS:
// For citizens who have been allocated slots previously
while (selected != nullptr && selected->visible)
{
if (selected->slot_date == today) // Citizens whose slot is today
{
selected->slot_today = true; // Modifies the citizen's slot_today member
selected = selected->next;
}
else
{
// Citizens whose slot occurred yesterday, but who failed to get vaccinated,
// need to be removed to the end of the queue-list (demoted) so they can be assigned fresh slots.
selected = selected->next; // Preserving the traversal before moving the element
int new_priority = cqueue.get_min_priority() - 1;
dq = cqueue.dequeue();
dq->visible = false;
dq->slot_today = false;
dq->demoted = true;
dq->priority = new_priority;
dq->slot_date = "Not Alloted Yet.";
cqueue.enqueue(dq);
}
}
string dslot = get_next_date(day, month, year); // Generates the string representation for the following day.
// Allocates the following day's slot to the citizens and enables them to check their date slots.
// Only a maximum of 'available_shots' number of citizens can be allocated a slot on a given day.
for (int count = 1; count <= available_shots; count++)
{
if (selected == nullptr)
break;
selected->slot_date = dslot;
selected->visible = true;
selected = selected->next;
}
last_date = today; // Modifies the last_date member to today's date
return true;
}
void Admin::display_top_n(CitizenQueueList &cqueue)
{
unsigned n;
cout << "\n\tHow many entries are to be displayed ?";
cin >> n;
cqueue.display_top_n(n);
}
void Admin::display_today(CitizenQueueList &cqueue)
{
cqueue.display_today();
}
void Admin::change_eligibility(CitizenQueueList &cqueue)
{
/*
* Allows admin to change the minimum eligibility age
*/
cout << "\n\tEnter eligibility age : ";
cin >> age_eligibility;
remove_age_ineligible(cqueue);
cout << "\n\t\tChanged successfully." << endl;
}
void Admin::change_available_shots()
{
/*
* Allows admin to change available_shots as per actual availability
*/
cout << "\n\tEnter new number : ";
cin >> available_shots;
cout << "Changed successfully." << endl;
}
void Admin::remove(Citizen *user, string pswd, CitizenQueueList &cqueue)
{
cqueue.remove(user, pswd);
}
void Admin::remove_age_ineligible(CitizenQueueList& cqueue)
{
Citizen* cur = cqueue.front;
Citizen* prev = nullptr;
Citizen* to_delete = nullptr;
bool delete_flag = false;
while(cur != nullptr){
delete_flag = cur->age < age_eligibility && !cur->visible;
if (delete_flag)
{
if (prev == nullptr) // Removing from the front
cqueue.front = cur->next;
else // Removing from other positions
prev->next = cur->next;
if (cqueue.rear == cur) // Removing from rear
cqueue.rear = prev;
to_delete = cur;
cur = cur->next;
to_delete->next = nullptr;
delete(to_delete);
}
else
{
prev = cur; // change prev only if cur is not to be deleted
cur = cur->next;
}
}
}
// ======================================================================================================
#endif /* ADMIN_H_ */