-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_do_list.cpp
96 lines (85 loc) · 2.15 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
#include<iostream>
using namespace std;
struct Task{
string task_description;
bool completed;
};
Task tasks[100];
int numTasks = 0;
void addTask(string task_description){
tasks[numTasks] = {task_description, false};
cout<<"Task added with id "<< numTasks+1<<endl;
numTasks++;
}
void viewTasks(){
cout<<"To-Do List:\n "<<endl;
for(int i=0; i<numTasks; i++){
cout<<i+1<<". "<<tasks[i].task_description;
if (tasks[i].completed){
cout<<"[DONE]"<<endl;
}
else{
cout<<"[PENDING]"<<endl;
}
}
}
void markascompleted(int taskId){
if(taskId < numTasks){
tasks[taskId].completed=true;
}
else{
cout<<"Task not found!"<<endl;
}
}
void removeTask(int taskId) {
if (taskId <= numTasks) {
for (int i = taskId-1; i <= numTasks ; i++) {
tasks[i] = tasks[i + 1];
}
numTasks--;
}
else {
cout << "Task not found!" << endl;
}
}
int main() {
int choice;
while (true) {
cout << "1. Add task\n";
cout << "2. View tasks\n";
cout << "3. Mark as completed\n";
cout << "4. Remove task\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
string description;
int taskId;
switch (choice) {
case 1:
cout << "Enter description: ";
cin>>description;
addTask(description);
break;
case 2:
viewTasks();
break;
case 3:
cout << "Enter task id: ";
cin >> taskId;
markascompleted(taskId);
break;
case 4:
cout << "Enter task id: ";
cin >> taskId;
removeTask(taskId);
break;
case 5:
exit(0);
default:
cout << "Invalid choice!\n";
break;
}
cout << endl;
}
return 0;
}