forked from dhairyagothi/Cpp-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
todolist.cpp
154 lines (138 loc) · 3.81 KB
/
todolist.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "pch.h"
using namespace winrt;
using namespace Windows::Foundation;
#include <iostream>
using namespace std;
const int maxTasks = 10; // Define the maximum number of tasks
class task_input
{
private:
string tasks[maxTasks];
string status[maxTasks];
int num = 0;
public:
void task()
{
cout << "\n Choose one of the following actions you want to perform: " << endl;
cout << " 1. ADD A TASK TO YOUR TO-DO LIST " << endl;
cout << " 2. VIEW TASK LIST " << endl;
cout << " 3. UPDATE TASK STATUS " << endl;
cout << " 4. REMOVE TASK FROM LIST " << endl;
cout << " 5. SHOW TASK STATUS " << endl;
cout << " 6. EXIT TODO LIST " << endl;
}
void addtask(const string& description)
{
if (num < maxTasks)
{
tasks[num] = description;
status[num] = "incomplete";
num++;
cout << " Task added successfully " << endl;
}
else
{
cout << "Task list is full." << endl;
}
}
void viewtask()
{
cout << "Here is your task list : "<<endl ;
for (int i = 0; i < num; i++)
{
cout << (i + 1) << "." << tasks[i] << " status: " << status[i] << endl;
}
}
void updatetaskstatus(int tasknum, const string& updatestatus)
{
if (tasknum >= 1 && tasknum <= num)
{
status[tasknum - 1] = updatestatus;
cout << "Task status updated successfully." << endl;
}
else
{
cout << "Invalid task number. Please enter a correct task number." << endl;
}
}
void taskliststatus()
{
cout << "Here is your task list status : "<<endl ;
for (int i = 0; i < num; i++)
{
cout << "TASK " << (i + 1) << ". status: " << status[i] << endl;
}
}
void removetask(int tasknum)
{
if (tasknum >= 1 && tasknum <= num)
{
for (int i = tasknum - 1; i < num - 1; i++)
{
tasks[i] = tasks[i + 1];
status[i] = status[i + 1];
}
num--;
cout << "Task removed successfully." << endl;
}
else
{
cout << "Invalid task number." << endl;
}
}
};
int main()
{
cout << "_____________________TO DO LIST____________________" << endl;
task_input list1; // Moved outside the loop to keep the task list
while (true)
{
list1.task();
int choice;
string description;
int tasknum;
string updatestatus;
cout << "Enter your choice: "<<endl;
cin >> choice;
cin.ignore(); // Added to consume the newline character
if (choice == 1)
{
cout << "Please enter your task: "<<endl;
getline(cin, description);
list1.addtask(description);
}
else if (choice == 2)
{
list1.viewtask();
}
else if (choice == 3)
{
cout << "Enter task number whose status you want to update: ";
cin >> tasknum;
cin.ignore();
cout << "Update task status (completed, incomplete, in progress): ";
getline(cin, updatestatus);
list1.updatetaskstatus(tasknum, updatestatus);
}
else if (choice == 4)
{
cout << "Enter Task no. to remove from the list: ";
cin >> tasknum;
list1.removetask(tasknum);
}
else if (choice == 5)
{
list1.taskliststatus();
}
else if (choice == 6)
{
cout << "Goodbye!" << endl;
break;
}
else
{
cout << "Please enter a valid input from the list." << endl;
}
}
return 0;
}