-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.h
More file actions
352 lines (298 loc) · 10.5 KB
/
TaskManager.h
File metadata and controls
352 lines (298 loc) · 10.5 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#ifndef TASKMANAGER_H
#define TASKMANAGER_H
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include "Task.h"
#include "PriorityQueue.h"
using namespace std;
class TaskManager
{
private:
PriorityQueue taskQueue;
vector<Task> completedTasks;
int nextTaskId;
// Encouraging quotes for when all tasks are done
vector<string> encouragingQuotes = {
"Outstanding work! You've conquered all your tasks!",
"You're a productivity superstar! All tasks completed!",
"Excellent job! Take a well-deserved break!",
"Mission accomplished! You're unstoppable!",
"All done! Your dedication is truly inspiring!",
"Fantastic work! You've cleared your task list like a pro!",
"Success! Every task checked off. Time to celebrate!",
"Amazing! You've proven that nothing is impossible!",
"Bravo! Your hard work has paid off beautifully!",
"You did it! All tasks completed with flying colors!"};
// Get random encouraging quote
string getRandomQuote()
{
srand(time(0));
int index = rand() % encouragingQuotes.size();
return encouragingQuotes[index];
}
// Clear input buffer
void clearInput()
{
cin.clear();
cin.ignore(10000, '\n');
}
// Validate date format (basic validation: DD/MM/YYYY)
bool isValidDate(const string &date)
{
if (date.length() != 10)
return false;
if (date[2] != '/' || date[5] != '/')
return false;
return true;
}
public:
TaskManager() : nextTaskId(1) {}
// ===== REQUIREMENT 1: Read/Add Task =====
void addTask()
{
cout << "\n=============================================" << endl;
cout << " ADD NEW TASK " << endl;
cout << "=============================================" << endl;
string title, description, assignDate, endDate, empName;
int priority;
clearInput();
cout << "Enter Task Title: ";
getline(cin, title);
cout << "Enter Task Description: ";
getline(cin, description);
cout << "Enter Assigning Date (DD/MM/YYYY): ";
getline(cin, assignDate);
while (!isValidDate(assignDate))
{
cout << "Invalid format! Enter Assigning Date (DD/MM/YYYY): ";
getline(cin, assignDate);
}
cout << "Enter Required Ending Date (DD/MM/YYYY): ";
getline(cin, endDate);
while (!isValidDate(endDate))
{
cout << "Invalid format! Enter Ending Date (DD/MM/YYYY): ";
getline(cin, endDate);
}
cout << "Enter Employee Name: ";
getline(cin, empName);
cout << "Enter Priority (1-10, where 10 is most important): ";
cin >> priority;
while (priority < 1 || priority > 10)
{
cout << "Invalid! Enter Priority (1-10): ";
cin >> priority;
}
// Create and insert task
Task newTask(nextTaskId++, title, description, assignDate, endDate, empName, priority);
taskQueue.insert(newTask);
cout << "\n>> Task added successfully with ID: " << (nextTaskId - 1) << " <<" << endl;
}
// ===== REQUIREMENT 4: Display Sorted Priority List =====
void displayAllTasks()
{
taskQueue.displayAll();
}
// ===== REQUIREMENT 5: Mark Task as Done =====
void markTaskDone()
{
if (taskQueue.isEmpty())
{
cout << "\n>> No tasks available to mark as done! <<" << endl;
return;
}
cout << "\n=============================================" << endl;
cout << " MARK TASK AS DONE " << endl;
cout << "=============================================" << endl;
displayAllTasks();
int taskId;
cout << "\nEnter Task ID to mark as done: ";
cin >> taskId;
Task *task = taskQueue.findById(taskId);
if (task != nullptr)
{
task->isDone = true;
completedTasks.push_back(*task);
taskQueue.removeById(taskId);
cout << "\n>> Task \"" << task->title << "\" marked as completed! <<" << endl;
// Check if all tasks are done
if (taskQueue.isEmpty())
{
displayCompletionMessage();
}
}
else
{
cout << "\n>> Task with ID " << taskId << " not found! <<" << endl;
}
}
// ===== REQUIREMENT 6: Reminder for Next Task =====
void showNextTaskReminder()
{
if (taskQueue.isEmpty())
{
cout << "\n=============================================" << endl;
cout << " NO PENDING TASKS " << endl;
cout << "=============================================" << endl;
cout << " Great job! You have no pending tasks. " << endl;
return;
}
cout << "\n=============================================" << endl;
cout << " NEXT TASK REMINDER " << endl;
cout << "=============================================" << endl;
cout << " >> Your highest priority task is: << " << endl;
taskQueue.getTop().display();
cout << "\n >> Focus on this task first! << " << endl;
}
// ===== REQUIREMENT 7: Encouraging Quote =====
void displayCompletionMessage()
{
cout << "\n*********************************************" << endl;
cout << "* *" << endl;
cout << "* ALL TASKS COMPLETED! *" << endl;
cout << "* *" << endl;
cout << "*********************************************" << endl;
cout << "\n\"" << getRandomQuote() << "\"" << endl;
cout << "\n*********************************************" << endl;
}
// ===== BONUS: Edit Task =====
void editTask()
{
if (taskQueue.isEmpty())
{
cout << "\n>> No tasks available to edit! <<" << endl;
return;
}
cout << "\n=============================================" << endl;
cout << " EDIT TASK " << endl;
cout << "=============================================" << endl;
displayAllTasks();
int taskId;
cout << "\nEnter Task ID to edit: ";
cin >> taskId;
Task *task = taskQueue.findById(taskId);
if (task == nullptr)
{
cout << "\n>> Task with ID " << taskId << " not found! <<" << endl;
return;
}
cout << "\nWhat would you like to edit?" << endl;
cout << "1. Title" << endl;
cout << "2. Description" << endl;
cout << "3. Priority" << endl;
cout << "4. Employee Name" << endl;
cout << "0. Cancel" << endl;
cout << "Choice: ";
int choice;
cin >> choice;
clearInput();
switch (choice)
{
case 1:
{
cout << "Enter new Title: ";
getline(cin, task->title);
cout << "\n>> Title updated successfully! <<" << endl;
break;
}
case 2:
{
cout << "Enter new Description: ";
getline(cin, task->description);
cout << "\n>> Description updated successfully! <<" << endl;
break;
}
case 3:
{
int newPriority;
cout << "Enter new Priority (1-10): ";
cin >> newPriority;
while (newPriority < 1 || newPriority > 10)
{
cout << "Invalid! Enter Priority (1-10): ";
cin >> newPriority;
}
taskQueue.updatePriority(taskId, newPriority);
cout << "\n>> Priority updated successfully! <<" << endl;
break;
}
case 4:
{
cout << "Enter new Employee Name: ";
getline(cin, task->employeeName);
cout << "\n>> Employee Name updated successfully! <<" << endl;
break;
}
case 0:
cout << "\n>> Edit cancelled. <<" << endl;
break;
default:
cout << "\n>> Invalid choice! <<" << endl;
}
}
// ===== BONUS: Postpone Task =====
void postponeTask()
{
if (taskQueue.isEmpty())
{
cout << "\n>> No tasks available to postpone! <<" << endl;
return;
}
cout << "\n=============================================" << endl;
cout << " POSTPONE TASK " << endl;
cout << "=============================================" << endl;
displayAllTasks();
int taskId;
cout << "\nEnter Task ID to postpone: ";
cin >> taskId;
Task *task = taskQueue.findById(taskId);
if (task == nullptr)
{
cout << "\n>> Task with ID " << taskId << " not found! <<" << endl;
return;
}
clearInput();
string newDate;
cout << "Current Ending Date: " << task->endingDate << endl;
cout << "Enter New Ending Date (DD/MM/YYYY): ";
getline(cin, newDate);
while (!isValidDate(newDate))
{
cout << "Invalid format! Enter New Ending Date (DD/MM/YYYY): ";
getline(cin, newDate);
}
task->endingDate = newDate;
cout << "\n>> Task postponed to " << newDate << " successfully! <<" << endl;
}
// Display completed tasks history
void displayCompletedTasks()
{
if (completedTasks.empty())
{
cout << "\n=============================================" << endl;
cout << " No completed tasks yet! " << endl;
cout << "=============================================" << endl;
return;
}
cout << "\n=============================================" << endl;
cout << " COMPLETED TASKS " << endl;
cout << "=============================================" << endl;
for (const Task &task : completedTasks)
{
task.display();
}
}
// Get task count
int getPendingCount() const
{
return taskQueue.size();
}
int getCompletedCount() const
{
return completedTasks.size();
}
};
#endif // TASKMANAGER_H