-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTO-DO LIST
111 lines (91 loc) · 2.58 KB
/
TO-DO LIST
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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Task {
string description;
bool isCompleted;
Task(string desc) {
description = desc;
isCompleted = false;
}
};
void addTask(vector<Task> &tasks) {
cout << "Enter task description: ";
string description;
cin.ignore();
getline(cin, description);
tasks.push_back(Task(description));
cout << "Task added successfully!" << endl;
}
void viewTasks(const vector<Task> &tasks) {
if (tasks.empty()) {
cout << "No tasks available!" << endl;
return;
}
cout << "\nYour Tasks:\n";
for (size_t i = 0; i < tasks.size(); ++i) {
cout << i + 1 << ". " << tasks[i].description << " ["
<< (tasks[i].isCompleted ? "Completed" : "Pending") << "]" << endl;
}
}
void markTaskCompleted(vector<Task> &tasks) {
viewTasks(tasks);
if (tasks.empty()) return;
cout << "\nEnter the task number to mark as completed: ";
int taskNumber;
cin >> taskNumber;
if (taskNumber > 0 && taskNumber <= tasks.size()) {
tasks[taskNumber - 1].isCompleted = true;
cout << "Task marked as completed!" << endl;
} else {
cout << "Invalid task number!" << endl;
}
}
void removeTask(vector<Task> &tasks) {
viewTasks(tasks);
if (tasks.empty()) return;
cout << "\nEnter the task number to remove: ";
int taskNumber;
cin >> taskNumber;
if (taskNumber > 0 && taskNumber <= tasks.size()) {
tasks.erase(tasks.begin() + taskNumber - 1);
cout << "Task removed successfully!" << endl;
} else {
cout << "Invalid task number!" << endl;
}
}
int main() {
vector<Task> tasks;
int choice;
do {
cout << "\nTo-Do List Menu:\n";
cout << "1. Add Task\n";
cout << "2. View Tasks\n";
cout << "3. Mark Task as Completed\n";
cout << "4. Remove Task\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
addTask(tasks);
break;
case 2:
viewTasks(tasks);
break;
case 3:
markTaskCompleted(tasks);
break;
case 4:
removeTask(tasks);
break;
case 5:
cout << "Exiting... Goodbye!" << endl;
break;
default:
cout << "Invalid choice! Please try again." << endl;
}
} while (choice != 5);
return 0;
}