-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodo.cpp
More file actions
146 lines (118 loc) · 4.08 KB
/
Todo.cpp
File metadata and controls
146 lines (118 loc) · 4.08 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
#include<iostream>
#include<list>
#include<string>
#include<ctime>
#include <chrono>
#include <iomanip>// for put time
using namespace std;
using namespace chrono;
class TodoItem
{
private:
int id;
string description;
bool completed;
public:
TodoItem() : id(0), description(""), completed(false) {} // constructor
~TodoItem() {} // destructor
bool create ( string new_description){
id = rand()%1000+1;
description = new_description;
return true;
}
int getId(){
return id;
}
string getDescription(){
return description;
}
bool isCompleted(){
return completed;
}
void setCompleted(bool val){
completed = val;
}
};
int main()
{
string input_description;
int input_ID;
char input_Option;
std::string v = __VERSION__;
list<TodoItem> todoItems;
list<TodoItem>::iterator it;
srand(time(NULL));
todoItems.clear();
// this is for test that created list is fine or not
// TodoItem test;
// test.create("Do 5 DSA Question Today!");
// todoItems.push_back(test);
while(1)
{
system("cls");
cout << "TO Do List in C++ " << v <<endl;
for(it = todoItems.begin(); it!= todoItems.end(); it++){
string completed = it->isCompleted() ? "done" : "not doned";
cout << it->getId() << " | " << it->getDescription() << " | " << completed<< endl;
}
if(todoItems.empty())
{
auto now = system_clock::now(); //convet time
time_t now_time = system_clock::to_time_t(now); // convert to time t
cout << "Add a Todo fo Today " << put_time(localtime(&now_time), "%Y-%m-%d %H:%M:%S") <<endl;
}
cout << " " << endl;
cout << "Enter a for add a New Todo !" <<endl;
cout << "Enter c for complete a TOdo !" <<endl;
cout << "Enter q for quit " << endl;
cout << "Choice : ";
cin >> input_Option;
cout << " " << endl;
if(input_Option == 'q')
{
cout << "Thanks for quit, have a great Day !" << endl;
cout << "Lets we meet again next day BUDDY!" << endl;
break;
}
else if (input_Option == 'c')
{
cout << "Enter ID of your To do you want to mark Complete : " ;
cin >>input_ID;
for(it = todoItems.begin(); it!= todoItems.end(); it++)
{
if(it->getId() == input_ID)
{
it->setCompleted(true);
cout << input_ID << " : Marked Completed" << endl;
break;
} else
{
cout << "You entered wrong ID" << endl;
}
}
} else if (input_Option == 'a')
{
cout <<"Enter How many task you want to Enter" <<endl;
int num;
cin >> num;
while (num != 0)
{
cout <<"Now add your New Task !" << endl;
cin.clear();
cin.ignore();
getline(cin, input_description);
TodoItem newItem;
newItem.create(input_description);
todoItems.push_back(newItem);
num--;
}
}
// it just to check every thig right during writing code
// for(it = todoItems.begin(); it!= todoItems.end(); it++){
// string completed = it->isCompleted() ? "done" : "not doned";
// cout << it->getId() << " | " << it->getDescription() << " | " << completed<< endl;
// }
// break;
}
return 0;
}