-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdated.cpp
More file actions
134 lines (113 loc) · 3.43 KB
/
updated.cpp
File metadata and controls
134 lines (113 loc) · 3.43 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
#include <iostream>
#include <string>
#include <list>
#include <ctime>
#include <cstdlib> // Include for rand() and srand()
#include <limits>
class Item
{
private:
int id;
std::string description;
bool completed;
public:
Item();
bool create(const std::string &new_description)
{
// Generates a random int between 1 and 100
id = rand() % 100 + 1;
description = new_description;
return true;
}
int getId()
{
return id;
}
std::string getDescription()
{
return description;
}
bool isComplete()
{
return completed;
}
// int getId() const { return id; }
// std::string getDescription() const { return description; }
// bool isCompleted() const { return completed; }
void setCompleted(bool val)
{
completed = val;
}
};
Item::Item() : id(0), description(""), completed(false)
{
}
int main()
{
std::list<Item> todoItems;
std::list<Item>::iterator it;
int user_choice;
int user_input_id;
std::string user_input_description;
srand(static_cast<unsigned int>(time(NULL))); // Use static_cast to avoid warning
while (true)
{
system("cls");
std::cout << "Welcome to the To-Do List.\n\n";
if (todoItems.empty())
{
std::cout << "The to-do list is empty. Add an entry.\n\n";
}
else
{
for (Item item : todoItems)
{
std::string completed = item.isComplete() ? "Task Completed" : "Task Not Completed";
std::cout << "Task ID: " << item.getId() << " | "
<< "Task Description: " << item.getDescription() << " | "
<< "Task Status: " << completed << std::endl;
}
}
std::cout << "\n1. Add a new To-Do item.\n";
std::cout << "2. Complete a To-Do item.\n";
std::cout << "3. Quit.\n\n";
std::cout << "Enter your choice: ";
std::cin >> user_choice;
if (user_choice == 3)
{
std::cout << "Thanks for using the To-Do Application.";
break;
}
else if (user_choice == 1)
{
std::cout << "Add a new To-Do item: ";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Use numeric_limits to clear input buffer
std::getline(std::cin, user_input_description);
Item newTodoItem;
newTodoItem.create(user_input_description);
todoItems.push_back(newTodoItem);
}
else if (user_choice == 2)
{
std::cout << "Enter the id of the item you want to complete: ";
std::cin >> user_input_id;
for (it = todoItems.begin(); it != todoItems.end(); it++)
{
std::string completed = it->isComplete() ? "Task Complete" : "Task Not Complete";
std::cout << "Task ID: " << it->getId() << " | "
<< "Task Description: " << it->getDescription() << " | "
<< "Completion Status: " << completed << std::endl;
if (user_input_id == it->getId())
{
it->setCompleted(true);
break;
}
else
{
std::cout << "ID does not exist. Try again.\n";
}
}
}
}
return 0;
}