-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDo_List.cpp
More file actions
85 lines (75 loc) · 2 KB
/
Copy pathToDo_List.cpp
File metadata and controls
85 lines (75 loc) · 2 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
#include <iostream>
#include <vector>
using namespace std;
struct Task {
string description;
bool completed;
};
vector<Task> todoList;
void displayMenu() {
cout << "=== To-Do List ===" << endl;
cout << "1. Add Task" << endl;
cout << "2. Mark Task as Completed" << endl;
cout << "3. Display List" << endl;
cout << "4. Quit" << endl;
cout << "==================" << endl;
cout << "Enter your choice: ";
}
void addTask() {
Task newTask;
cout << "Enter task description: ";
cin.ignore();
getline(cin, newTask.description);
newTask.completed = false;
todoList.push_back(newTask);
cout << "Task added successfully!" << endl;
}
void markTaskAsCompleted() {
int index;
cout << "Enter the index of the task to mark as completed: ";
cin >> index;
if (index >= 0 && index < todoList.size()) {
todoList[index].completed = true;
cout << "Task marked as completed!" << endl;
} else {
cout << "Invalid index!" << endl;
}
}
void displayList() {
cout << "=== To-Do List ===" << endl;
for (size_t i = 0; i < todoList.size(); ++i) {
cout << "[" << i << "] ";
if (todoList[i].completed) {
cout << "[X] ";
} else {
cout << "[ ] ";
}
cout << todoList[i].description << endl;
}
cout << "==================" << endl;
}
int main() {
int choice;
do {
displayMenu();
cin >> choice;
switch (choice) {
case 1:
addTask();
break;
case 2:
markTaskAsCompleted();
break;
case 3:
displayList();
break;
case 4:
cout << "Goodbye!" << endl;
break;
default:
cout << "Invalid choice!" << endl;
break;
}
} while (choice != 4);
return 0;
}