-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskList.h
More file actions
107 lines (89 loc) · 2.05 KB
/
TaskList.h
File metadata and controls
107 lines (89 loc) · 2.05 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
#include <string>
#include <string.h>
#include <iostream>
using namespace std;
class Task {
friend class TaskList;
private:
string toDo; //task to do
Task* next; //next pointer to point to next task in queue
public:
Task(); //constructor
};
Task::Task() { //constructor definition
toDo = " ";
next = NULL;
}
class TaskList { //Queue of things to do
private:
Task* head;
Task* tail;
int score; //points for completing a task
public:
TaskList(); //constructor
string pop();
void pushBack(string task);
void traverseList();
int displayScore();
void addPoints();
bool isEmpty(); //Is anything in list?
};
TaskList::TaskList() { //constructor definition
head = NULL;
tail = NULL;
score = 0;
}
void TaskList::pushBack(string task) { //Adds a new task to the end of the queue
Task *newTask = new Task;
newTask->toDo = task;
if (head == NULL) {
head = newTask;
tail = newTask;
}
else {
tail->next = newTask;
tail = newTask;
}
}
string TaskList::pop() { //Returns a task to do from the queue in FIFO ordering
string taskToDo = " ";
string errorMessage = "There is nothing currently in the list!";
Task* removal; //pointer to be deleted
if (head == NULL) {
return errorMessage;
}
else {
taskToDo = head->toDo;
removal = head;
head = head->next;
delete removal; //free up memory
return taskToDo;
}
}
void TaskList::traverseList() {
Task *curr; //pointer to follow
cout << "Currently on the ToDo List: " << endl;
if (head == NULL) {
cout << "There is nothing currently in your ToDo list! " << endl;
}
else {
for (curr = head; curr != NULL; curr = curr->next) {
cout << curr->toDo << endl;
}
}
}
void TaskList::addPoints() {
score += 5;
cout << "5 points have been added to your score for completing the task! Your total score now is " << displayScore() << "." << endl;
}
int TaskList::displayScore() {
return score;
}
bool TaskList::isEmpty() {
if (head == NULL) {
return true;
}
else {
return false;
}
}