-
Notifications
You must be signed in to change notification settings - Fork 0
/
To-Do-List.cpp
140 lines (125 loc) · 3.57 KB
/
To-Do-List.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class ToDoList {
public:
vector<string> list = {"list is empty"};
void addTask();
void viewTask(int n);
void viewAllTasks();
void removeTask();
void markAsCompleted();
void updateTask();
void menu();
};
void ToDoList::updateTask() {
viewAllTasks();
cout << "\nPlease select a task number to Update: ";
int n;
cin >> n;
if (n > 0 && n < list.size()) {
cout << "Please edit the task: ";
string temp;
cin.ignore();
getline(cin, temp);
list[n] = temp;
cout << "\nTask '" << list[n - 1] << "' is Updated" << endl;
} else {
cout << "Invalid task number. Please try again." << endl;
}
}
void ToDoList::removeTask() {
viewAllTasks();
cout << "\nPlease select a task number to Delete: ";
int n;
cin >> n;
if (n > 0 && n < list.size()) {
cout << "\nTask '" << list[n - 1] << "' is Deleted" << endl;
list.erase(list.begin() + (n - 1));
} else {
cout << "Invalid task number. Please try again." << endl;
}
}
void ToDoList::viewAllTasks() {
cout << "\n-------------------------------------" << endl;
if (list.size() == 1) {
cout << list[0] << endl;
} else {
for (int i = 1; i < list.size(); i++) {
cout << i << ". " << list[i] << endl;
}
}
cout << "-------------------------------------" << endl;
}
void ToDoList::viewTask(int n) {
cout << list[n] << endl;
}
void ToDoList::addTask() {
cout << "\n-------------------------------------" << endl;
cout << "Please add your task " << list.size() << ": ";
string temp;
cin.ignore();
getline(cin, temp);
list.push_back(temp);
cout << "Task '" << list.back() << "' is successfully added to your list."
<< endl;
cout << "-------------------------------------" << endl;
}
void ToDoList::markAsCompleted() {
viewAllTasks();
cout << "\nPlease select a task number to mark as completed: ";
int n;
cin >> n;
if (n > 0 && n < list.size()) {
cout << "\nTask '" << list[n - 1] << "' is completed" << endl;
list.erase(list.begin() + (n - 1));
} else {
cout << "Invalid task number. Please try again." << endl;
}
}
void ToDoList::menu() {
while (true) {
cout << "\n-------------------------------" << endl;
cout << " TASK MANAGER" << endl;
cout << "-------------------------------" << endl;
cout << "1. Add a New Task" << endl;
cout << "2. View All Tasks" << endl;
cout << "3. Mark Task as Completed" << endl;
cout << "4. Remove Task" << endl;
cout << "5. Update Task" << endl;
cout << "6. Exit" << endl;
cout << "-------------------------------" << endl;
cout << "Enter your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1:
addTask();
break;
case 2:
viewAllTasks();
break;
case 3:
markAsCompleted();
break;
case 4:
removeTask();
break;
case 5:
updateTask();
break;
case 6:
cout << "Exiting the program..." << endl;
return;
default:
cout << "Invalid choice. Please try again." << endl;
}
}
}
int main() {
ToDoList list1;
list1.menu();
return 0;
}