-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTASK4.cpp
More file actions
94 lines (81 loc) · 2.25 KB
/
TASK4.cpp
File metadata and controls
94 lines (81 loc) · 2.25 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Task {
string description;
bool completed;
};
vector<Task> tasks;
void addTask() {
Task newTask;
cout << "Enter the task description: ";
cin.ignore();
getline(cin, newTask.description);
newTask.completed = false;
tasks.push_back(newTask);
cout << "Task added successfully.\n";
}
void viewTasks() {
if (tasks.empty()) {
cout << "No tasks available.\n";
return;
}
cout << "\n--- To-Do List ---\n";
for (size_t i = 0; i < tasks.size(); ++i) {
cout << i + 1 << ". [" << (tasks[i].completed ? "X" : " ") << "] "
<< tasks[i].description << "\n";
}
cout << endl;
}
void markTaskCompleted() {
viewTasks();
if (tasks.empty()) return;
int index;
cout << "Enter the task number to mark as completed: ";
cin >> index;
if (index > 0 && index <= tasks.size()) {
tasks[index - 1].completed = true;
cout << "Task marked as completed.\n";
} else {
cout << "Invalid task number.\n";
}
}
void removeTask() {
viewTasks();
if (tasks.empty()) return;
int index;
cout << "Enter the task number to remove: ";
cin >> index;
if (index > 0 && index <= tasks.size()) {
tasks.erase(tasks.begin() + index - 1);
cout << "Task removed successfully.\n";
} else {
cout << "Invalid task number.\n";
}
}
void showMenu() {
cout << "\n====== TO-DO LIST MANAGER ======\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 << "Choose an option (1-5): ";
}
int main() {
int choice;
do {
showMenu();
cin >> choice;
switch (choice) {
case 1: addTask(); break;
case 2: viewTasks(); break;
case 3: markTaskCompleted(); break;
case 4: removeTask(); break;
case 5: cout << "Exiting the To-Do List Manager.\n"; break;
default: cout << "Invalid choice. Try again.\n";
}
} while (choice != 5);
return 0;
}