-
Notifications
You must be signed in to change notification settings - Fork 0
/
Todo_list.cpp
103 lines (77 loc) · 2.5 KB
/
Todo_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
97
98
99
100
101
102
103
#include <iostream>
#include <string>
#include <list>
#include <ctime>
class TodoItem {
private:
int id;
std::string description;
bool completed;
public:
TodoItem() : id(0), description(""), completed(false) {}
~TodoItem() = default;
bool create(std::string new_description) {
// generates a random integer between 1 and 100
id = rand() % 100 + 1;
description = new_description;
return true;
}
int getId() { return id; }
std::string getDescription() { return description; }
bool isCompleted() { return completed; }
void setCompleted(bool val) { completed = val; }
};
int main()
{
char input_option;
int input_id;
std::string input_description;
std::string version = "v0.2.0";
std::list<TodoItem> todoItems;
std::list<TodoItem>::iterator it;
srand(time(NULL));
todoItems.clear();
while (1) {
system("cls");
std::cout << "Todo List Maker - " << version << std::endl;
std::cout << std::endl << std::endl;
for (it = todoItems.begin(); it != todoItems.end(); it++) {
std::string completed = it->isCompleted() ? "done" : "not done";
std::cout << it->getId() << " | " << it->getDescription() << " | "
<< completed << std::endl;
}
if (todoItems.empty()) {
std::cout << "Add your first todo!" << std::endl;
}
std::cout << std::endl << std::endl;
std::cout << "[a]dd a new Todo" << std::endl;
std::cout << "[c]omplete a Todo" << std::endl;
std::cout << "[q]uit" << std::endl;
std::cout << "choice: ";
std::cin >> input_option;
if (input_option == 'q') {
std::cout << "Have a great day now!" << std::endl;
break;
}
else if (input_option == 'a') {
std::cout << "Add a new description: ";
std::cin.clear();
std::cin.ignore();
std::getline(std::cin, input_description);
TodoItem newItem;
newItem.create(input_description);
todoItems.push_back(newItem);
}
else if (input_option == 'c') {
std::cout << "Enter id to mark completed: ";
std::cin >> input_id;
for (it = todoItems.begin(); it != todoItems.end(); it++) {
if (input_id == it->getId()) {
it->setCompleted(true);
break;
}
}
}
}
return 0;
}