-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.cpp
More file actions
252 lines (221 loc) · 5.04 KB
/
TaskManager.cpp
File metadata and controls
252 lines (221 loc) · 5.04 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
/*
* Playlist.cpp
*
* Created on: Oct 4, 2020
* Author: 13027
*/
#include "TaskManager.hpp"
#include <fstream>
#include <stdlib.h>
#include <iostream>
#include <sstream>
using namespace std;
TaskManager::TaskManager() {
list = new DLL();
readList("ListofTasks.txt");
//cout<< " within taskManager constructor" << endl;
list->printList();
cout << endl;
interface();
}
TaskManager::TaskManager(string s) {
list = new DLL();
//cout<< " within taskManager constructor - string s " << endl;
readList(s);
list->printList();
cout << endl;
interface();
}
void TaskManager::interface() {
int choice=0;
while (choice != 8) {
cout << "\n What do you want to do?" <<endl<< flush;
cout <<"Enter:" << endl<< flush;
cout <<"\t1 for adding a task"<<endl<< flush;
cout <<"\t2 for removing a task" << endl<< flush;
cout <<"\t3 for moving a task up in the list" << endl<< flush;
cout <<"\t4 for moving a task down in the list" << endl<< flush;
cout <<"\t5 for changing the priority of a task" << endl<< flush;
cout <<"\t6 for getting a list of tasks with priority p"<< endl<<flush;
cout <<"\t7 for printing the list "<<endl<<flush;
cout <<"\t8 for exit" <<endl<< flush;
cin >> choice;
if (choice ==1) {
addTask();
}
else if (choice == 2) {
removeTask();
}
else if (choice == 3) {
moveUp();
}
else if (choice == 4) {
moveDown();
}
else if (choice ==5) {
changePriorityofTask();
list->printList();
}
else if (choice ==6){
getPriorityTasks();
}
else if (choice == 7) {
list->printList();
}
else if (choice == 8) {
ByeNow();
}
}
}
void TaskManager::changePriorityofTask() {
cout<<"Changing a Task's Priority:" <<endl;
cout << "Enter the task number:" <<endl << flush;
int tnum;
cin >> tnum;
cout << "Enter the task's new priority" << endl<< flush;
int pnum;
cin >> pnum;
if (tnum >0 && pnum > 0) {
list->changePriority(tnum,pnum);
//list->printList();
}
}
void TaskManager::getPriorityTasks() {
int mintot = 0;
int hrtot = 0;
cout << "Enter the priority you want: "<<endl;
int prio;
cin >> prio;
list->listDuration(&hrtot, &mintot,prio);
cout << "The total time needed to complete tasks of priority "<<prio<<" is ";
cout << hrtot<<":"<<mintot<<endl;
cout << endl<<flush;
list->printList(prio);
return;
}
void TaskManager::moveUp() {
cout<<"Moving a Task Up:" <<endl;
cout << "Enter the task number:" <<endl << flush;
int tnum;
cin >> tnum;
if (tnum >0) {
list->moveUp(tnum);
list->printList();
}
}
string TaskManager::getTitle() {
string str = "";
while (str == "") {
getline(cin, str);
}
string title;
title = strip(str);
return title;
}
void TaskManager::moveDown() {
cout<<"Moving a Task Down:" <<endl;
cout << "Enter the task number:" <<endl << flush;
int tnum;
cin >> tnum;
if (tnum >0) {
list->moveDown(tnum);
list->printList();
}
}
void TaskManager::removeTask() {
cout<<"Removing a task:" <<endl;
cout << "Enter the number of the task you wish to remove" <<endl << flush;
int tnum;
cin >> tnum;
if (tnum >0) {
list->remove(tnum);
cout << "Did you complete the task (yes or no)?" << endl << flush;
string s;
cin >> s;
if (s == "yes") {
cout << "WOO WOO!!! One less thing to do!!!" << endl;
}
list->printList();
}
}
void TaskManager::addTask() {
cout<<"Adding a task:" <<endl;
cout << "Enter the task as follows: task, priority, hrs:mins" <<endl << flush;
string taskstr = "";
while (taskstr == "") {
getline(cin, taskstr);
}
string task;
task = strip(taskstr);
string pris;
string hrs;
string mins;
pris = strip(taskstr);
int prio = 0;
stringstream tmp(pris);
tmp>>prio;
hrs = strip(taskstr);
int hr = 0;
stringstream tmp2(hrs);
tmp2>>hr;
mins = taskstr;
stringstream tmp3(mins);
int min = 0;
tmp3>>min;
cout << task<<":::"<<pris<<":::"<<hrs<<":::"<<mins<<":::"<<endl;
if (task.length() >0) {
list->push(task,prio,hr,min);
list->printList();
}
}
void TaskManager::ByeNow() {
cout << "Bye Now!" << endl;
return;
}
string TaskManager::strip(string &s) {
const char* WhiteSpace = " \t\v\r\n";
size_t start = s.find_first_not_of(WhiteSpace);
const char* EndChar = ":,\n";
size_t end = s.find_first_of(EndChar);
string s2;
int len = s.length();
if (start<end){
s2=s.substr(start,end-start);
s = s.substr(end+1,len-end+1);
}
return s2;
}
void TaskManager::readList(string f) {
ifstream file(f.c_str());
string taskstr;
string task;
string pris;
string mins;
string hrs;
while (!file.eof()) {
getline(file,taskstr);
cout << taskstr<<endl;
task = strip(taskstr);
pris = strip(taskstr);
int prio = 0;
stringstream tmp(pris);
tmp>>prio;
hrs = strip(taskstr);
int hr = 0;
stringstream tmp2(hrs);
tmp2>>hr;
mins = taskstr;
stringstream tmp3(mins);
int min = 0;
tmp3>>min;
cout << task<<":::"<<pris<<":::"<<hrs<<":::"<<mins<<":::"<<endl;
//cout << "hi" << endl;
if (task.length() >0) {
//cout<<"before push"<<endl;
list->push(task,prio,hr,min);
//cout<<"after push "<<endl;
}
}
cout <<"*********DONE READING**************************"<<endl<<endl;
return;
}