-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask4_TO_DO_LIST.cpp
More file actions
90 lines (75 loc) · 2.36 KB
/
Task4_TO_DO_LIST.cpp
File metadata and controls
90 lines (75 loc) · 2.36 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Struct to represent a task
struct Task {
string description;
bool done;
};
// Function to show all tasks
void showTasks(const vector<Task>& tasks) {
if (tasks.empty()) {
cout << "No tasks found.\n";
return;
}
for (int i = 0; i < tasks.size(); i++) {
cout << i + 1 << ". " << tasks[i].description;
cout << " [" << (tasks[i].done ? "Done" : "Not done") << "]\n";
}
}
int main() {
vector<Task> tasks;
int choice;
do {
cout << "\n=== SIMPLE TO-DO LIST ===\n";
cout << "1. Add Task\n";
cout << "2. Show Tasks\n";
cout << "3. Mark Task as Done\n";
cout << "4. Delete Task\n";
cout << "5. Exit\n";
cout << "Enter choice: ";
cin >> choice;
cin.ignore(); // Ignore leftover newline
if (choice == 1) {
string desc;
cout << "Enter task: ";
getline(cin, desc);
tasks.push_back({desc, false});
cout << "Task added.\n";
} else if (choice == 2) {
showTasks(tasks);
} else if (choice == 3) {
showTasks(tasks);
if (!tasks.empty()) {
int num;
cout << "Enter task number to mark as done: ";
cin >> num;
if (num >= 1 && num <= tasks.size()) {
tasks[num - 1].done = true;
cout << "Task marked as done.\n";
} else {
cout << "Invalid task number.\n";
}
}
} else if (choice == 4) {
showTasks(tasks);
if (!tasks.empty()) {
int num;
cout << "Enter task number to delete: ";
cin >> num;
if (num >= 1 && num <= tasks.size()) {
tasks.erase(tasks.begin() + num - 1);
cout << "Task deleted.\n";
} else {
cout << "Invalid task number.\n";
}
}
} else if (choice == 5) {
cout << "Exiting....\n";
} else {
cout << "Invalid choice. Try again.\n";
}
} while (choice != 5);
return 0;
}