-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoDoList.cpp
More file actions
306 lines (262 loc) · 8.58 KB
/
toDoList.cpp
File metadata and controls
306 lines (262 loc) · 8.58 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int ID;
struct list
{
int id;
string task;
string status;
};
void addlist() {
system("cls");
cout << "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< "\t\t\t\t WELCOME TO Your ToDo List " << endl
<< "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< endl << endl;
list list;
cout << "\n Enter new task > ";
cin.get();
getline(cin, list.task);
cout << " Enter its status > " ;
getline(cin, list.status);
cout<< endl;
ID++;
ofstream write; // Write to list.txt
write.open("list.txt", ios::app);
write << "\n" << ID << "\n" << list.task << "\n" << list.status;
write.close();
write.open("id.txt"); // Write to list.txt
write << ID;
write.close();
char ch;
cout << " Do you want to add more tasks? (y/n): ";
cin >> ch;
cout<<endl;
if (ch == 'y') {
addlist();
} else {
cout << "\n--------------------Task and its Status have been added successfully--------------------";
return;
}
}
void print(list s)
{
cout << "\n\tID is : " << s.id;
cout << "\n\tTask is : " << s.task;
cout << "\n\tStatus is : " << s.status;
}
void readData()
{
system("cls");
cout << "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< "\t\t\t\t WELCOME TO Your ToDo List " << endl
<< "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< endl << endl;
struct list
{
int id;
string task;
string status;
};
ifstream read;
read.open("list.txt");
if (!read.is_open())
{
cout << "Error opening the file. Make sure 'list.txt' exists." << endl;
return;
}
cout << "\n--------------------------| Your current Tasks in the list |------------------------" << endl
<<endl;
list list;
while (read >> list.id)
{
read.ignore();
getline(read, list.task);
getline(read, list.status);
cout << "ID: " << list.id <<endl
<< "Task: " << list.task << endl
<< "Status: " << list.status << endl
<< "---------------------------------------------------------------------------------" << endl;
}
read.close(); // Close the file stream
}
int searchData()
{
system("cls");
cout << "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< "\t\t\t\t WELCOME TO Your ToDo List " << endl
<< "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< endl << endl;
int id;
cout << "\n\tEnter task id: ";
cin >> id;
list list;
ifstream read;
read.open("list.txt");
while (!read.eof())
{
read >> list.id;
read.ignore();
getline(read, list.task);
getline(read, list.status);
if (list.id == id)
{
print(list);
return id;
}
}
}
void deleteData()
{
system("cls");
cout << "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< "\t\t\t\t WELCOME TO Your ToDo List " << endl
<< "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< endl << endl;
int id = searchData();
cout << "\n\tDo you want to delete this task (y/n) : ";
char choice;
cin >> choice;
if (choice == 'y')
{
list list;
ofstream tempFile;
tempFile.open("temp.txt");
ifstream read;
read.open("list.txt");
while (!read.eof())
{
read >> list.id;
read.ignore();
getline(read, list.task);
// read.ignore();
getline(read, list.status);
if (list.id != id)
{
tempFile << "\n"
<< list.id;
tempFile << "\n"
<< list.task;
tempFile << "\n"
<< list.status;
}
}
read.close();
tempFile.close();
remove("list.txt");
rename("temp.txt", "list.txt");
remove("id.txt");
cout << "\n\tTask deleted successfuly";
}
else
{
cout << "\n\tRecord not deleted";
}
}
void updateData()
{
system("cls");
cout << "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< "\t\t\t\t WELCOME TO Your ToDo List " << endl
<< "\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
<< endl << endl;
int id = searchData();
cout << "\n\tYou want to update this task (y/n) : ";
char choice;
cin >> choice;
if (choice == 'y')
{
list newData;
cout << "\n\tEnter todo task : ";
cin.get();
getline(cin, newData.task);
cout << endl;
cout << "\n\t Enter the update status: ";
cin.get();
getline(cin, newData.status);
list list;
ofstream tempFile;
tempFile.open("temp.txt");
ifstream read;
read.open("list.txt");
while (!read.eof())
{
read >> list.id;
read.ignore();
getline(read, list.task);
getline(read, list.status);
if (list.id != id)
{
tempFile << "\n"
<< list.id;
tempFile << "\n"
<< list.task;
tempFile << "\n"
<< list.status;
}
else
{
tempFile << "\n"
<< list.id;
tempFile << "\n"
<< newData.task;
tempFile << "\n"
<< newData.status;
}
}
read.close();
tempFile.close();
remove("list.txt");
rename("temp.txt", "list.txt");
cout << "\n\t Task updated successfuly" << endl
<< "\n\t Status updated successfully";
}
else
{
cout << "\n\tRecord not deleted";
}
}
int main()
{
system("cls");
system("title todoapp @copyassignment");
cout << "\t\t\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl
<< "\t\t\t\t!! !!" << endl
<< "\t\t\t\t!! WELCOME TO YOUR TODO LIST !!" << endl
<< "\t\t\t\t!! !!" << endl
<< "\t\t\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl
<< endl << endl << endl;
ifstream read;
read.open("id.txt");
if (!read.fail())
{
read >> ID;
}
else
{
ID = 0;
}
read.close();
while (true)
{
cout << "\n\n"
<< "1. Add Task" << "\t\t2. View Tasks" << "\t\t3. Search Task"
<<"\t\t4. Delete Task"<< "\t\t5. Update Task"<<"\t\t0. Close List \n\n";
int choice;
cout << "\nEnter your choice : ";
cin >> choice;
switch (choice)
{
case 1: addlist();break;
case 2: readData();break;
case 3: searchData();break;
case 4: deleteData();break;
case 5: updateData();break;
default: cout << "\n-------------------------------------< Thanks for using ToDo list >---------------------------------------------- ";
exit(0);
}
}
}