-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task4.cpp
102 lines (86 loc) · 2.02 KB
/
Task4.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
#include <bits/stdc++.h>
using namespace std;
//bool option=true;
struct Task{
string taskName;
bool completed;
};
vector<Task>tasks;
void addTask(){
string task;
cout<<"Enter the task:";
cin.ignore();
getline(cin,task);
tasks.push_back({task, false});
cout<<"Task added: "<<task<<endl;
/*option =0;
cout<<"Do yo want to return (true/false)";
cin>>option;*/
}
void showTasks() {
if (tasks.empty()) {
cout << "No tasks found\n";
} else {
for (int i = 0; i < tasks.size(); i++) {
string status = tasks[i].completed ? "Completed" : "Pending";
cout << i + 1 << "- " << tasks[i].taskName << " - " << status << endl;
}
}
}
void completeTask(){
showTasks();
int num;
cout<<"Enter the task number to mark it as completed:";
cin>>num;
if(num >=1&&num<=tasks.size()){
tasks[num-1].completed=true;
cout<<"Task marked as completed.\n";
}
else
cout<<"Invalid task number.\n";
}
void removeTask(){
showTasks();
int num;
cout<<"Enter the task number to remove it:";
cin>>num;
if(num >=1&&num<=tasks.size()){
cout<<"Task removed "<<tasks[num-1].taskName<<endl;
tasks.erase(tasks.begin()+num-1);
cout<<"Task marked as completed.\n";
}
else
cout<<"Invalid task number.\n";
}
int main(){
cout<<endl<<"TO-DO LIST\n";
while (true){
cout<<"\n Options:\n";
cout<<"1- Add task.\n";
cout<<"2- View tasks. \n";
cout<<"3- Mark as complete. \n";
cout<<"4- Remove task. \n";
cout<<"5- Quit. \n";
int choice;
cout<<"Enter your choice:";
cin>>choice;
switch (choice) {
case 1:
addTask();
break;
case 2:
showTasks();
break;
case 3:
completeTask();
break;
case 4:
removeTask();
break;
case 5:
return 0;
default:
cout<<"Invalid choice please try again! \n";
}
}
}