-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
173 lines (151 loc) · 4.17 KB
/
main.cpp
File metadata and controls
173 lines (151 loc) · 4.17 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
#include <bits/stdc++.h>
using namespace std;
// Constants
const int MAX_TASKS = 100;
// Task Data
struct Task {
int ID;
string Title;
string Description;
int Priority; // 1 (High) to 5 (Low)
string DueDate; // Format: YYYY-MM-DD
set<string> Tags; // Unique tags
};
// Function Prototypes
void Input_One_Task(Task &Cur_Task, int id);
void Input_Tasks(vector<Task> &Tasks);
void Display_Header();
void Display_Task(const Task &Cur_Task);
void Display_All_Tasks(const vector<Task> &Tasks);
void Sort_Tasks_By_Priority(vector<Task> &Tasks);
void Search_By_Tag(const vector<Task> &Tasks);
void Run_Task_System();
// --- Function Definitions ---
// Input a single task
void Input_One_Task(Task &Cur_Task, int id) {
Cur_Task.ID = id;
cin.ignore();
cout << "Enter Title: ";
getline(cin, Cur_Task.Title);
cout << "Enter Description: ";
getline(cin, Cur_Task.Description);
cout << "Enter Priority (1-5): ";
cin >> Cur_Task.Priority;
cin.ignore();
cout << "Enter Due Date (YYYY-MM-DD): ";
getline(cin, Cur_Task.DueDate);
cout << "Enter Tags (space-separated): ";
string line, tag;
getline(cin, line);
stringstream ss(line);
while (ss >> tag) {
Cur_Task.Tags.insert(tag);
}
}
// Input multiple tasks
void Input_Tasks(vector<Task> &Tasks) {
char choice;
do {
if (Tasks.size() >= MAX_TASKS) {
cout << "Reached Maximum Task Capacity\n";
break;
}
Task t;
Input_One_Task(t, Tasks.size() + 1);
Tasks.push_back(t);
cout << "Add another task? (Y/N): ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
}
// Display table header
void Display_Header() {
cout << left << setw(5) << "ID"
<< setw(20) << "Title"
<< setw(12) << "Priority"
<< setw(15) << "Due Date"
<< "Tags\n";
cout << "--------------------------------------------------------------\n";
}
// Display a single task
void Display_Task(const Task &Cur_Task) {
cout << left << setw(5) << Cur_Task.ID
<< setw(20) << Cur_Task.Title
<< setw(12) << Cur_Task.Priority
<< setw(15) << Cur_Task.DueDate;
for (const string &tag : Cur_Task.Tags) {
cout << tag << " ";
}
cout << "\n";
}
// Display all tasks
void Display_All_Tasks(const vector<Task> &Tasks) {
cout << "\n===== Task Records =====\n";
Display_Header();
for (const Task &t : Tasks) {
Display_Task(t);
}
}
// Sort tasks by priority
void Sort_Tasks_By_Priority(vector<Task> &Tasks) {
sort(Tasks.begin(), Tasks.end(), [](const Task &a, const Task &b) {
return a.Priority < b.Priority;
});
cout << "✅ Sorted by Priority.\n";
}
// Search tasks by tag
void Search_By_Tag(const vector<Task> &Tasks) {
string tag;
cout << "Enter tag to search: ";
cin >> tag;
cin.ignore();
bool found = false;
cout << "\n--- Tasks With Tag [" << tag << "] ---\n";
for (const Task &t : Tasks) {
if (t.Tags.count(tag)) {
Display_Task(t);
found = true;
}
}
if (!found) {
cout << "❌ No tasks found with that tag.\n";
}
}
// Control system
void Run_Task_System() {
vector<Task> Tasks;
int choice;
do {
cout << "\n=== Task Management System ===\n";
cout << "1. Add Tasks\n";
cout << "2. View All Tasks\n";
cout << "3. Sort by Priority\n";
cout << "4. Search by Tag\n";
cout << "5. Exit\n";
cout << "Choose an option: ";
cin >> choice;
switch (choice) {
case 1:
Input_Tasks(Tasks);
break;
case 2:
Display_All_Tasks(Tasks);
break;
case 3:
Sort_Tasks_By_Priority(Tasks);
break;
case 4:
Search_By_Tag(Tasks);
break;
case 5:
cout << "👋 Exiting...\n";
break;
default:
cout << "❌ Invalid choice.\n";
}
} while (choice != 5);
}
// Main function
int main() {
Run_Task_System();
return 0;
}