-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
659 lines (620 loc) · 20.9 KB
/
main.cpp
File metadata and controls
659 lines (620 loc) · 20.9 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
#include "Base.hpp"
#include "Date.hpp"
#include "task.hpp"
#include "subtask.hpp"
#include "project.hpp"
#include "TaskFactory.cpp"
#include "SubtaskFactory.cpp"
#include "ProjectFactory.cpp"
#include "FileIO.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <algorithm>
using namespace std;
FileIO Fio;
vector <project *>proj;
vector <subtask *>subt;
vector <task *>tasks;
char option;
char s[80];
void viewAllTask();
void viewIncTask();
void viewProject();
void PromptTask();
void viewTodayTask();
void viewDateTask();
void viewPriorityTask();
void viewComTask();
void viewIncTask();
void viewDateTask();
void showSubtasks(task *t);
bool compare(task* t1,task*t2){
if(t1->get_date_obj().getYear() < t2->get_date_obj().getYear())
return true;
if((t1->get_date_obj().getYear() == t2->get_date_obj().getYear()) && (t1->get_date_obj().getMonth() < t2->get_date_obj().getMonth()))
return true;
if((t1->get_date_obj().getYear() == t2->get_date_obj().getYear()) && (t1->get_date_obj().getMonth() < t2->get_date_obj().getMonth())&&(t1->get_date_obj().getDay() && t1->get_date_obj().getDay()))
return true;
return false;
}
void setToday(){
const int MAXLEN = 80;
time_t t = time(0);
strftime(s, MAXLEN, "%m/%d/%Y", localtime(&t));
}
task* taskSearch(string name){
for(int i=0; i<tasks.size(); i++){
if(tasks[i]->getName() == name){
return tasks[i];
}
}
return NULL;
}
project* projectSearch(string name){
for(int i=0; i<proj.size(); i++){
if(proj[i]->getName() == name){
return proj[i];
}
}
return NULL;
}
subtask* subtaskSearch(string name){
for(int i=0; i<subt.size(); i++){
if(subt[i]->getName() == name){
return subt[i];
}
}
return NULL;
}
void printMenu(){
cout << " Select an option from the Menu:" << endl;
cout << " A - Add A Task" << endl;
cout << " B - Add A Subtask" << endl;
cout << " C - Mark Task As Completed" << endl;
cout << " D - Create A Project" << endl;
cout << " E - Mark Project As Completed" << endl;
cout << " F - View Tasks" << endl; //ask user for all tasks today,via priority, or via date
cout << " G - View Projects" << endl;
cout << " Please enter Q or q to quit... " << endl;
}
// Creates a Task
task* usertask(){
TaskFactory * tfactory = new TaskFactory();
string name;
string date;
string description;
int priority;
cout << " Enter name of task: " << endl;
getline(cin >> ws, name);
//cin.clear();
//cin.ignore(10000, '\n');
cout << " Enter task description: " << endl;
getline(cin >> ws, description);
//cin.clear();
//cin.ignore(10000, '\n');
cout << " Enter task due date (Please enter in Month/Day/Year format): " << endl;
getline(cin >> ws, date);
//cin.clear();
// cin.ignore(10000, '\n');
cout << " Enter the level of task priority from a level of 1-5 (1 being low priority, 5 being the most urgent): " << endl;
cin >> priority;
task* newtask = tfactory->create(name, description, date, priority);
tasks.push_back(newtask);
delete tfactory;
return newtask;
//append into tasks vector
}
// Asks for an existing Incomplete task and creates a Subtask to be assigned.
Base* userSubTask(){
SubtaskFactory * sfactory = new SubtaskFactory();
string taskname;
task* t;
string name;
string date;
string description;
bool complete;
int priority;
viewIncTask();
cout << " Enter name of Task: " << endl;
getline(cin >> ws, taskname);
//cin.clear();
//cin.ignore(10000, '\n');
t = taskSearch(taskname);
if (t == NULL){
cout << " Task not found. Please try again." << endl;
delete sfactory;
return nullptr;
}else{
//cin.clear();
//cin.ignore(10000, '\n');
cout << " Enter name of sub-task: " << endl;
getline(cin >> ws, name);
//cin.clear();
// cin.ignore(10000, '\n');
cout << " Enter sub-task description: " << endl;
getline(cin >> ws, description);
//cin.clear();
//cin.ignore(10000, '\n');
cout << " Enter sub-task due date (Please enter in Month/Day/Year format): " << endl;
getline(cin >> ws, date);
//cin.clear();
//cin.ignore(10000, '\n');
cout << " Enter the level of sub-task priority from a level of 1-5 (1 being low priority, 5 being the most urgent): " << endl;
cin >> priority;
subtask* newtask = sfactory->createSubtask(name, description, date, priority, complete);
subt.push_back(newtask);
t->add_subtask(newtask);
delete sfactory;
return newtask;
}
}
// Creates an Empty Project
Base* userProject(){
ProjectFactory * ffactory = new ProjectFactory();
string name;
string description;
string date;
cout << " Enter name of project: " << endl;
getline(cin >> ws, name);
//cin.clear();
// cin.ignore(10000, '\n');
cout << " Enter project description: " << endl;
getline(cin >> ws, description);
//cin.clear();
//cin.ignore(10000, '\n');/
cout << " Enter project due date (Please enter in Month/Day/Year format): " << endl;
getline(cin >> ws, date);
//cin.clear();
//cin.ignore(10000, '\n');
project* newProject = ffactory->create(name, description, date);
proj.push_back(newProject);
delete ffactory;
return newProject;
}
// Marks a task as complete (need to check subtasks)
Base* markTaskComplete(){
task* task = nullptr;
string taskName = "";
viewIncTask();
cout << "Please type the name of the task you wish to mark complete" << endl;
getline(cin >> ws, taskName);
//cin.clear();
//cin.ignore(10000, '\n');
task = taskSearch(taskName);
if (task == NULL){
cout << "Task not found. Please try again." << endl;
}else{
task->mark_as_complete();
cout<<"Task has been marked as complete."<<endl;
cout<<endl;
}
}
//INCOMPLETE
Base* makeProjectComplete(){
char op2;
cout<< "WARNING: Any Items in the project will be marked as completed"<<endl;
cout<<"proceed? (Y/N)"<<endl;
cin >> op2;
if (op2 =='Y' || op2 == 'y'){
string projName;
cout << "Please type the name of the project you wish to mark complete" << endl;
getline(cin >> ws, projName);
project *p = projectSearch(projName);
if (p == NULL) {
cout << "Project not found. Please try again." << endl;
} else {
vector<Base *> taskVec = p->get_items(); // taskVec = all tasks in project p
for (size_t i = 0; i < taskVec.size(); i++) { // iterate over every element in project
Base *b = taskVec.at(i); // b = base pointer for current element in project
task *t = dynamic_cast<task*>(b); // t = cast to task to use get_subtasks, has_subtasks, and subtask::mark_as_complete()
if (t->has_subtasks()) { // if task held at current element has subtasks, iterate over them and mark as complete
vector<subtask*> subVec = t->get_subtasks();
for (size_t j = 0; j < subVec.size(); j++) {
subVec[j]->mark_as_complete();
}
t->mark_as_complete(); // once subtasks are completed, this should complete task
} else {
t->mark_as_complete(); // if no subtasks, mark the task as complete
}
}
p->mark_as_complete();
}
}
else if (op2 == 'N' || op2 =='n'){
return nullptr;
}
else{
cout << "INVALID RESPONSE" << endl;
}
}
//Ask user if they wish to select a particular task.
void TaskSelect(){
char op1;
cout << "Would you like to select a Task? (Y/N)" << endl;
cin >> op1;
if (op1 =='Y' || op1 == 'y'){
PromptTask();
}
else if (op1 == 'N' || op1 =='n'){
return;
}
else{
cout << "INVALID RESPONSE" << endl;
return;
}
}
//prints Tasks Menu
void viewTaskMenu(){
cout << " Select an option from the Menu:" << endl;
cout << " A - Show Today's tasks" << endl;
cout << " B - Show tasks via date" << endl;
cout << " C - Show tasks via priority" << endl;
cout << " D - Show Completed Tasks" << endl;
cout << " E - Show Incomplete Tasks" << endl;
cout << " F - Show All Tasks" << endl;
cout << " Q - Return to Main Menu" << endl;
}
//Print Task Operation Menu
void printTaskOperations(){
cout << " Select an option from the Menu:" << endl;
cout << " A - Mark Task Incomplete (Completed Tasks Only)" << endl;
cout << " B - Remove Subtask" << endl;
cout << " C - View Subtasks" << endl;
cout << " D - View Full Task Details" << endl;
cout << " Q - Return to Main Menu" << endl;
}
// View Tasks and check in tasks is empty
void promptTaskView(){
bool hascompleted = false;
bool isIncomplete = false;
char op5;
viewTaskMenu();
cin >> op5;
if (op5 =='A' || op5 == 'a'){
if (tasks.empty()){
cout<<"No tasks to show"<<endl;
}else{
viewTodayTask();
TaskSelect();
}
}
else if (op5 == 'B' || op5 =='b'){
if (tasks.empty()){
cout<<"No tasks to show"<<endl;
}else{
viewDateTask();
TaskSelect();
}
}
else if(op5 =='C' || op5 == 'c'){
if (tasks.empty()){
cout<<"No tasks to show"<<endl;
}else{
viewPriorityTask();
TaskSelect();
}
}
else if(op5 == 'D' || op5 == 'd'){
for (int i = 0; i < tasks.size(); i++){
if (tasks[i]->complete() == true){
hascompleted = true;
}
}
if (hascompleted == false){
cout << "No completed tasks" << endl;
}else{
viewComTask();
TaskSelect();
}
}
else if(op5 == 'E' || op5 == 'e'){
for (int i = 0; i < tasks.size(); i++){
if (tasks[i]->complete() == false){
isIncomplete = true;
}
}
if (isIncomplete == true){
viewIncTask();
TaskSelect();
}else{
cout << "All Tasks Complete!" << endl;
}
}else if(op5 == 'F' || op5 == 'f'){
if (tasks.empty()){
cout<<"No tasks to show"<<endl;
}else{
viewAllTask();
TaskSelect();
}
}else if(op5 == 'Q' || op5 == 'q'){
return;
}else{
cout << "Invalid input. Please try again." << endl;
}
}
//ALL TASK PRINTS
void viewAllTask(){
for (int i = 0; i < tasks.size(); i++){
cout << "Name: " << tasks[i]->getName() << endl;
cout << " Description: " << tasks[i]->getDescription() << endl;
cout << " Due Date: " << tasks[i]->get_date() << endl;
cout << " Priority: " << tasks[i]->get_priority() << endl;
cout << " Completion: " << boolalpha << tasks[i]->complete() << endl;
cout << " Has Subtasks: " << boolalpha<< tasks[i]->has_subtasks() << endl;
}
}
void viewIncTask(){ //prints Incomplete tasks no sorting
for(int i=0; i<tasks.size(); i++){
if(!tasks[i]->complete()){
cout << "Name: " << tasks[i]->getName() << endl;
cout << " Description: " << tasks[i]->getDescription() << endl;
if (tasks[i] ->get_date() != " "){
if(tasks[i]->get_priority() != 0){
cout << " Due Date: " << tasks[i]->get_date() << endl;
cout << " Priority: " << tasks[i]->get_priority() << endl;
}
}
cout << " Has Subtasks: " << boolalpha << tasks[i]->has_subtasks() << endl;
}
}
}
void viewComTask(){ //prints Complete tasks no sorting
for(int i=0; i<tasks.size(); i++){
if(tasks[i]->complete()){
cout << "Name: " << tasks[i]->getName() << endl;
cout << " Description: " << tasks[i]->getDescription() << endl;
if (tasks[i] ->get_date() != " "){
if(tasks[i]->get_priority() != 0){
cout << " Due Date: " << tasks[i]->get_date() << endl;
cout << " Priority: " << tasks[i]->get_priority() << endl;
}
}
cout << " Has Subtasks: " << boolalpha << tasks[i]->has_subtasks() << endl;
}
}
}
void viewTodayTask(){
cout <<"Today's Tasks"<< endl;
for(int i=0; i<tasks.size();i++){
if(tasks[i]->get_date() == s){
if(!tasks[i]->complete()){
cout << "Name: " << tasks[i]->getName() << endl;
cout << " Description: " << tasks[i]->getDescription() << endl;
if (tasks[i] ->get_date() != " "){
if(tasks[i]->get_priority() != 0){
cout << " Due Date: " << tasks[i]->get_date() << endl;
cout << " Priority: " << tasks[i]->get_priority() << endl;
}
}
cout << " Has Subtasks: " << boolalpha << tasks[i]->has_subtasks() << endl;
}
}
}
}
void viewDateTask(){
vector<task*> dateSorted(tasks);
sort(dateSorted.begin(),dateSorted.end(),compare);
for(int i=0; i<dateSorted.size(); i++){
if(!dateSorted[i]->complete()){
cout << "Name: " << tasks[i]->getName() << endl;
cout << " Description: " << tasks[i]->getDescription() << endl;
if (dateSorted[i] ->get_date() != " "){
if(dateSorted[i]->get_priority() != 0){
cout << " Due Date: " << tasks[i]->get_date() << endl;
cout << " Priority: " << tasks[i]->get_priority() << endl;
}
}
cout << " Has Subtasks: " << boolalpha << tasks[i]->has_subtasks() << endl;
}
}
}
void viewPriorityTask(){
for(int j =5; j >= 0; j--){
for(int i =0; i<tasks.size(); i++){
if(tasks[i]->get_priority() == j){
cout << "Name: " << tasks[i]->getName() << endl;
cout << " Description: " << tasks[i]->getDescription() << endl;
if (tasks[i] ->get_date() != " "){
if(tasks[i]->get_priority() != 0){
cout << " Due Date: " << tasks[i]->get_date() << endl;
cout << " Priority: " << tasks[i]->get_priority() << endl;
}
}
cout << " Has Subtasks: " << boolalpha << tasks[i]->has_subtasks() << endl;
}
}
}
}
//Searchs for the task and asks what to do with it
void PromptTask(){
task* task;
string taskName = "";
viewIncTask();
cout << "Please type the name of the task you wish to select." << endl;
getline(cin >> ws, taskName);
//cin.clear();
//cin.ignore(10000, '\n');
task = taskSearch(taskName);
if (task == NULL){
cout << "Task not found. Please try again." << endl;
}else{
printTaskOperations();
char op6;
cin >> op6;
if (op6 == 'A' || op6 == 'a'){
if(task->complete()){
task->mark_as_incomplete();
cout << "Task marked as incomplete." << endl;
}else{
cout << "Task already marked as incomplete." << endl;
}
}else if (op6 == 'B' || op6 == 'b'){
subtask* sub;
string subName;
showSubtasks(task);
if(task->has_subtasks()){
cout << "Please Select a Subtask to remove" << endl;
getline(cin >> ws, subName);
//cin.clear();
//cin.ignore(10000, '\n');
sub = task->remove_subtask(subName);
for (size_t i = 0; i < subt.size(); i++) {
if (subt.at(i) == sub) {
subt.erase(subt.begin() + i);
}
}
cout << "Subtask removed." << endl;
}else{
return;
}
}else if (op6 == 'C' || op6 == 'c'){
showSubtasks(task);
}else if (op6 == 'D' || op6 == 'd'){
cout << "Name: " << task->getName() << endl;
cout << " Description: " << task->getDescription() << endl;
cout << " Due Date: " << task->get_date() << endl;
cout << " Priority: " << task->get_priority() << endl;
cout << " Completion: " << task->complete() << endl;
cout << " Subtasks: " << task->has_subtasks() << endl;
if(task->has_subtasks()){
showSubtasks(task);
}
}else if (op6 == 'Q' || op6 == 'Q'){
return;
}else{
cout << "Invalid input. Please try again." << endl;
return;
}
}
/*
for(int i=0; i<tasks.size(); i++){
if(tasks[i]->getName() == taskName){
task = tasks[i];
}
}
if(task == nullptr){
cout<<"Sorry! Can't find your task"<<endl;
}else{
if(task->has_subtasks()){
cout << "This task has subtasks, do you like to view? (Y/N)"<<endl;
char subview;
cin >> subview;
if (subview =='Y' || subview == 'y'){
showSubtasks(task);
}
else if (subview == 'N' || subview =='n'){
return;
}
else{
cout << "INVALID RESPONSE" << endl;
}
}else{
cout << "Sorry no avaliable options for this task"<<endl;
}
}
*/
}
//Shows Subtasks from a task
void showSubtasks(task* t){
t->print_subtasks();
}
void viewProject(){
for(int i=0; i<proj.size(); i++){
cout << "Name: " << proj[i]->getName() <<endl;
cout << " Description: " << proj[i]->getDescription() << endl;
if (proj[i] ->get_date() != " "){
cout << " Due Date: " << proj[i]->get_date() << endl;
}
cout << " Completion: " << boolalpha << proj[i]->complete() << endl;
}
}
void establishConnection(task* newtask){
project* Addedproj = nullptr;
string projectName= "";
viewProject();
cout << "select the project you wish to add this task"<< endl;
getline(cin >> ws, projectName);
//cin.clear();
//cin.ignore(10000, '\n');
for(int i=0; i<proj.size(); i++){
if(proj[i]->getName() == projectName){
Addedproj = proj[i];
}
}
if (Addedproj == nullptr){
cout<<"Sorry! Can't find your project"<<endl;
}else{
Addedproj->add_item(newtask);
cout << "Added task to Project" <<endl;
}
}
void promptPTConnection(task* newtask){
char op3;
if(!proj.empty()){
cout << "Would you like to add this task to a Project?(Y/N)" << endl;
cin >> op3;
if (op3 =='Y' || op3 == 'y'){
establishConnection(newtask);
}
else if (op3 == 'N' || op3 =='n'){
return;
}
else{
cout << "INVALID RESPONSE" << endl;
}
}else{
return;
}
}
int main(){
Fio.readTask("tasks.txt");
Fio.readSub("sub.txt");
Fio.readProject("proj.txt");
Fio.readTaskRelations("task_rel.txt",tasks,subt);
Fio.readProjectRelations("proj_rel.txt",proj,tasks);
setToday();
cout<< " Welcome to the Task Scheduler! "<<endl;
do{
printMenu();
cin >> option;
cout << endl;
if (option =='A' || option == 'a'){
task* newtask = usertask();
promptPTConnection(newtask);
}
else if (option == 'B' || option =='b'){
userSubTask();
}
else if(option =='C' || option == 'c'){
markTaskComplete();
}
else if(option == 'D' || option == 'd'){
userProject();
}
else if(option == 'E' || option == 'e'){
makeProjectComplete();
}
else if(option == 'F' || option == 'f'){
promptTaskView();
}
else if(option == 'G' || option == 'g'){
viewProject();
}
}while(option != 'q' && option != 'Q');
Fio.writeTask("tasks.txt",tasks);
Fio.writeSub("sub.txt",subt);
Fio.writeProject("proj.txt",proj);
Fio.writeTaskRelations("task_rel.txt",tasks);
Fio.writeProjectRelations("proj_rel.txt",proj);
for (int i = 0; i < subt.size(); i++) {
delete subt[i];
}
for (int i = 0; i < proj.size(); i++) {
delete proj[i];
}
for (int i = 0; i < tasks.size(); i++) {
delete tasks[i];
}
}