-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentList.cpp
More file actions
167 lines (146 loc) · 5.03 KB
/
AssignmentList.cpp
File metadata and controls
167 lines (146 loc) · 5.03 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
// Alfred Ledgin
// 10/3/2015
// CS 303
// Project 1
#include <iostream>
#include "AssignmentList.h"
using namespace std;
const ostream& AssignmentList::displayAll(ostream& output)
{
for (AssignmentIterator = theData.begin();
AssignmentIterator != theData.end();
AssignmentIterator++)
{
AssignmentIterator->display(output);
}
return output;
}
bool AssignmentList::addAssignment(Assignment inputAssignment)
{
if (inputAssignment.hasInvalidDate())
return false;
if (!find(inputAssignment)) // Look for assignment with same assigned date.
{
if (!(inputAssignment.obtainDueDate() <=
inputAssignment.obtainAssignedDate()))
{
insert(inputAssignment);
if (inputAssignment.obtainStatus() == 2)
lateAssignments++; // Keep track of late assignments.
return true;
}
}
return false;
}
bool AssignmentList::completeAssignment(string inputAssignedDate,
string inputCompletedDate, AssignmentList& inputCompletedList)
{
for (AssignmentIterator = theData.begin();
AssignmentIterator != theData.end(); AssignmentIterator++)
// Find the assignment.
{
try
{
if (AssignmentIterator->obtainAssignedDate() ==
Date(inputAssignedDate))
{
if (Date(inputCompletedDate) > AssignmentIterator->obtainDueDate())
{
AssignmentIterator->setStatus(2);
lateAssignments++; // Keep track of late assignments.
}
else
AssignmentIterator->setStatus(1);
inputCompletedList.addAssignment(*AssignmentIterator);
// Move the completed assignment.
theData.remove(*AssignmentIterator);
// Reference: "std::list::remove." _cplusplus.com_.
// cplusplus.com, 2015. Web. 28 Sept. 2015.
// <http://www.cplusplus.com/reference/list/list/remove/>.
return true;
}
}
catch (std::exception)
{
return false;
}
}
return false;
}
bool AssignmentList::editAssignment(string inputAssignedDate,
string desiredDescription, string desiredDueDate)
{
for (AssignmentIterator = theData.begin();
AssignmentIterator != theData.end(); AssignmentIterator++)
// Find the assignment.
{
try
{
if (AssignmentIterator->obtainAssignedDate() ==
Date(inputAssignedDate))
{
if (AssignmentIterator->obtainStatus() == 0)
// Only edit assignments with the "assigned" status.
{
if (desiredDescription != "")
AssignmentIterator->setDescription(desiredDescription);
if (desiredDueDate != "")
{
AssignmentIterator->setDueDate(desiredDueDate);
Assignment tempAssignment = *AssignmentIterator;
theData.remove(*AssignmentIterator);
// Reference: "std::list::remove." _cplusplus.com_.
// cplusplus.com, 2015. Web. 28 Sept. 2015.
// <http://www.cplusplus.com/reference/list/list/remove/>.
insert(tempAssignment);
// Move the assignment if editing the due date.
}
return true;
}
}
}
catch (std::exception)
{
return false;
}
}
return false;
}
bool AssignmentList::find(Assignment inputAssignment)
{
for (AssignmentIterator = theData.begin();
AssignmentIterator != theData.end();
AssignmentIterator++)
{
if (AssignmentIterator->obtainAssignedDate()
== inputAssignment.obtainAssignedDate())
return true;
}
return false;
}
void AssignmentList::insert(Assignment inputAssignment)
{
if (!obtainSize()) // If the list is empty.
theData.push_front(inputAssignment);
else
{
for (AssignmentIterator = theData.begin();
AssignmentIterator != theData.end();
AssignmentIterator++)
{
// If we find an assignment with a later due date, insert this
// assignment before it and exit the function.
if (inputAssignment.obtainDueDate() <= AssignmentIterator->obtainDueDate())
{
theData.insert(AssignmentIterator, inputAssignment);
// Reference: "std::list::insert." _cplusplus.com_.
// cplusplus.com, 2015. Web. 2 Oct. 2015.
// <http://www.cplusplus.com/reference/list/list/insert/>.
return;
}
}
theData.push_back(inputAssignment);
// If we have not found an assignment with a later due date, place
// this assignment at the end of the list.
}
}