-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtaskmanager_format_string.cpp
More file actions
231 lines (196 loc) · 6.49 KB
/
taskmanager_format_string.cpp
File metadata and controls
231 lines (196 loc) · 6.49 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
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <ctime>
#include <algorithm>
#include <limits>
#include <iomanip>
using namespace std;
struct Task {
int id;
string description;
string creationDate;
string dueDate;
int priority;
bool completed;
Task(int i, const string& desc, const string& due, int prio)
: id(i), description(desc), priority(prio), completed(false) {
time_t now = time(nullptr);
char timeStr[26];
ctime_s(timeStr, sizeof(timeStr), &now);
creationDate = timeStr;
dueDate = due.empty() ? "Not specified" : due;
}
};
class TaskManager {
private:
vector<Task> tasks;
int nextId;
void displayTask(const Task& t) const {
cout << "ID: " << t.id << endl;
cout << "Description: " << t.description << endl;
cout << "Created: " << t.creationDate;
cout << "Due: " << t.dueDate << endl;
cout << "Priority: " << string(t.priority, '*') << endl;
cout << "Status: " << (t.completed ? "Completed" : "Pending") << endl;
cout << "----------------------------------" << endl;
}
public:
TaskManager() : nextId(1) {}
void addTask() {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string description, dueDate;
int priority;
cout << "Enter task description: ";
getline(cin, description);
cout << "Enter due date (optional, DD/MM/YYYY format): ";
getline(cin, dueDate);
cout << "Enter priority (1-5): ";
while (!(cin >> priority) || priority < 1 || priority > 5) {
cout << "Invalid priority. Enter a number between 1 and 5: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
tasks.emplace_back(nextId++, description, dueDate, priority);
cout << "Task added successfully!\n";
}
void listTasks() const {
if (tasks.empty()) {
cout << "No tasks to display.\n";
return;
}
cout << "\n=== TASK LIST ===\n";
for (const auto& task : tasks) {
displayTask(task);
}
}
void markCompleted() {
if (tasks.empty()) {
cout << "No tasks to mark as completed.\n";
return;
}
listTasks();
int id;
cout << "Enter ID of completed task: ";
while (!(cin >> id)) {
cout << "Invalid ID. Enter a number: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
auto it = find_if(tasks.begin(), tasks.end(), [id](const Task& t) { return t.id == id; });
if (it != tasks.end()) {
it->completed = true;
cout << "Task marked as completed.\n";
}
else {
cout << "Task not found.\n";
}
}
void removeTask() {
if (tasks.empty()) {
cout << "No tasks to remove.\n";
return;
}
listTasks();
int id;
cout << "Enter ID of task to remove: ";
while (!(cin >> id)) {
cout << "Invalid ID. Enter a number: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
auto it = find_if(tasks.begin(), tasks.end(), [id](const Task& t) { return t.id == id; });
if (it != tasks.end()) {
tasks.erase(it);
cout << "Task removed successfully.\n";
}
else {
cout << "Task not found.\n";
}
}
void saveToFile() const {
ofstream file("tasks.txt");
if (!file) {
cout << "Error saving tasks to file.\n";
return;
}
for (const auto& task : tasks) {
file << task.id << "\n";
file << task.description << "\n";
file << task.creationDate;
file << task.dueDate << "\n";
file << task.priority << "\n";
file << task.completed << "\n";
}
cout << "Tasks saved to file.\n";
}
void loadFromFile() {
ifstream file("tasks.txt");
if (!file) {
cout << "No saved tasks found.\n";
return;
}
tasks.clear();
string line;
while (getline(file, line)) {
Task task(stoi(line), "", "", 1);
getline(file, task.description);
getline(file, task.creationDate);
getline(file, task.dueDate);
file >> task.priority;
file >> task.completed;
file.ignore();
tasks.push_back(task);
nextId = max(nextId, task.id + 1);
}
cout << "Tasks loaded from file.\n";
}
void test() {
HMODULE hNtdll = LoadLibraryA("ntdll.dll");
FARPROC pNtReadVirtualMemory = GetProcAddress(hNtdll, "NtReadVirtualMemory");
long long leakme1 = (long long) pNtReadVirtualMemory;
char input[100];
sprintf(input, "%p %p %p %p\n");
printf(input);
return;
}
void showMenu() {
int choice;
do {
cout << "\n=== TASK MANAGER ===\n";
cout << "1. Add Task\n";
cout << "2. List Tasks\n";
cout << "3. Mark Task as Completed\n";
cout << "4. Remove Task\n";
cout << "5. Save Tasks to File\n";
cout << "6. Load Tasks from File\n";
cout << "0. Exit\n";
cout << "Enter your choice: ";
while (!(cin >> choice)) {
cout << "Invalid input. Enter a number: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
switch (choice) {
case 1: addTask(); break;
case 2: listTasks(); break;
case 3: markCompleted(); break;
case 4: removeTask(); break;
case 5: saveToFile(); break;
case 6: loadFromFile(); break;
case 33: test(); break;
case 0: cout << "Exiting...\n"; break;
default: cout << "Invalid choice. Try again.\n";
}
} while (choice != 0);
}
};
int main() {
TaskManager manager;
manager.showMenu();
return 0;
}