-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitial.cpp
More file actions
60 lines (47 loc) · 1.38 KB
/
Copy pathInitial.cpp
File metadata and controls
60 lines (47 loc) · 1.38 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct Task {
string title;
int priority;
bool completed;
};
class TaskManager {
private:
vector<Task> tasks;
public:
void addTask(const string& title, int priority) {
tasks.push_back({title, priority, false});
}
void completeTask(int index) {
if (index >= 0 && index < static_cast<int>(tasks.size())) {
tasks[index].completed = true;
}
}
void showTasks() const {
vector<Task> sorted = tasks;
sort(sorted.begin(), sorted.end(), [](const Task& a, const Task& b) {
return a.priority > b.priority;
});
cout << "Task Manager\n";
cout << "============\n";
for (size_t i = 0; i < sorted.size(); ++i) {
cout << i + 1 << ". "
<< "[" << (sorted[i].completed ? "Done" : "Open") << "] "
<< sorted[i].title
<< " | Priority: " << sorted[i].priority << '\n';
}
}
};
int main() {
TaskManager manager;
manager.addTask("Finish project", 5);
manager.addTask("Read documentation", 3);
manager.addTask("Fix login bug", 5);
manager.addTask("Update dependencies", 2);
manager.completeTask(1);
manager.showTasks();
return 0;
}