-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask4.cpp
More file actions
93 lines (84 loc) · 2.14 KB
/
Task4.cpp
File metadata and controls
93 lines (84 loc) · 2.14 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Task {
string description;
bool completed;
};
vector<Task> tasks;
void addTask() {
string desc;
cout << "Enter task description: ";
cin.ignore();
getline(cin, desc);
tasks.push_back({desc, false});
cout << "Task added successfully.\n";
}
void viewTasks() {
if (tasks.empty()) {
cout << "No tasks available.\n";
return;
}
cout << "Your Tasks:\n";
for (size_t i = 0; i < tasks.size(); ++i) {
cout << i + 1 << ". " << tasks[i].description
<< " [" << (tasks[i].completed ? "Completed" : "Pending") << "]\n";
}
}
void markCompleted() {
int num;
viewTasks();
cout << "Enter task number to mark as completed: ";
cin >> num;
if (num > 0 && num <= tasks.size()) {
tasks[num - 1].completed = true;
cout << "Task marked as completed.\n";
} else {
cout << "Invalid task number.\n";
}
}
void removeTask() {
int num;
viewTasks();
cout << "Enter task number to remove: ";
cin >> num;
if (num > 0 && num <= tasks.size()) {
tasks.erase(tasks.begin() + num - 1);
cout << "Task removed successfully.\n";
} else {
cout << "Invalid task number.\n";
}
}
int main() {
int choice;
do {
cout << "\n--- To-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();
break;
case 2:
viewTasks();
break;
case 3:
markCompleted();
break;
case 4:
removeTask();
break;
case 5:
cout << "Exiting To-Do List. Goodbye!\n";
break;
default:
cout << "Invalid choice. Try again.\n";
}
} while (choice != 5);
}