-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
216 lines (194 loc) · 4.62 KB
/
Copy pathprogram.cpp
File metadata and controls
216 lines (194 loc) · 4.62 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
#include <fstream>
#include <iomanip>
#include <iostream>
#include "program.h"
// Display welcome message
void Program::welcome()
{
std::cout << "Welcome to your task manager.\n";
}
// Main menu loop
void Program::menuLoop()
{
char input;
do
{
displayMenu();
std::cout << "\t>> ";
std::cin >> input;
system("clear");
switch (toupper(input))
{
case 'L':
loadFromCSV();
break;
case 'D':
printTaskList();
break;
case 'A':
addTask();
break;
case 'R':
removeFromList();
break;
case 'F':
printTaskList();
markTaskFinished();
break;
case 'S':
saveToCSV();
break;
case 'C':
clear();
break;
case 'Q':
std::cout << "Q";
return;
default:
std::cout << "Invalid option\n";
}
} while (true);
}
// Display menu options
void Program::displayMenu()
{
std::cout << "\nPick an option from the menu below:\n";
std::cout << "(L) Load tasks from CSV\n";
std::cout << "(D) Display list of tasks\n";
std::cout << "(A) Add a task\n";
std::cout << "(R) Remove a task\n";
std::cout << "(F) Mark a task finished\n";
std::cout << "(S) Save tasks to CSV\n";
std::cout << "(C) Clear task list\n";
std::cout << "(Q) Quit program\n";
}
// Print the task list
void Program::printTaskList()
{
list.printTaskList();
}
// Remove a task from the list
void Program::removeFromList()
{
if (list.isEmpty())
{
std::cout << "No tasks available";
return;
}
std::string input;
printTaskList();
std::cout << "Enter the task name or number to remove: \n\t>> ";
std::cin.ignore();
std::getline(std::cin, input);
// Check if the input is a positive integer
bool isInt = true;
for (size_t i = 0; i < input.size(); i++)
{
if (!isdigit(input[i]))
{
isInt = false;
break;
}
}
if (isInt)
{
int pos = std::stoi(input);
if (pos <= 0)
{
std::cout << "Invalid position.\n";
return;
}
list.removeFromList(pos, "");
}
else
{
list.removeFromList(-1, input);
}
}
// Mark a task as finished
void Program::markTaskFinished()
{
if (list.isEmpty())
{
std::cout << "No tasks available";
return;
}
std::string input;
std::cout << "Enter the task name or number to mark as finished: \n\t>> ";
std::cin.ignore();
std::getline(std::cin, input);
// Check if the input is a positive integer
bool isInt = true;
for (size_t i = 0; i < input.size(); i++)
{
if (!isdigit(input[i]))
{
isInt = false;
break;
}
}
if (isInt)
{
int pos = std::stoi(input);
if (pos <= 0)
{
std::cout << "Invalid position.\n";
return;
}
list.markTaskFinished(pos, "");
}
else
{
list.markTaskFinished(-1, input);
}
}
// Add a new task to the list
void Program::addTask()
{
std::string tempName;
std::cout << "\nWhat will the name of the task be?\n\t>> ";
std::cin >> tempName;
int tempPriority;
std::cout << "What will the priority of the task?\n\t (More important tasks get a lower priority)\n\t>> ";
std::cin >> tempPriority;
std::string tempDescription;
std::cout << "What will the task description be?\n\t>> ";
std::cin >> tempDescription;
Task newTask(tempName, tempPriority, tempDescription);
list.addToList(newTask);
}
// Load tasks from a CSV file
void Program::loadFromCSV()
{
std::string fileName;
std::cout << "Enter the name of the CSV file to load tasks from:\n\t>> ";
std::cin >> fileName;
if (list.loadFromCSV(fileName))
{
std::cout << "Tasks loaded from " << fileName << std::endl;
std::cout << "Total tasks loaded: " << list.getSize() << std::endl;
}
else
{
std::cout << "Failed to load tasks from " << fileName << ".\n";
}
}
void Program::saveToCSV()
{
std::string fileName;
std::cout << "Enter the name of the CSV file to save tasks to:\n\t>> ";
std::cin >> fileName;
if (list.saveToCSV(fileName))
{
std::cout << "Tasks saved to " << fileName << std::endl;
}
else
{
std::cout << "Failed to save tasks to " << fileName << ".\n";
}
}
void Program::clear()
{
list.clear();
std::cout << "Task list cleared.\n";
}