-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssignment.cpp
More file actions
154 lines (137 loc) · 4.23 KB
/
Assignment.cpp
File metadata and controls
154 lines (137 loc) · 4.23 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
//Christian Nissen
//cant4f@mail.umkc.edu
//uses Date.h and StringTokenizer.h classes provided by instructor
#include <string>
#include "Assignment.h"
#include "Date.h"
//#include "AssignStatus.h" //took out because i think i found a better way to do the enum
using namespace std;
//blank constructor, likely won't be used
Assignment::Assignment()
{
Description = "";
AssignStatus AssignmentStatus = AssignStatus::Assigned;
//provide a default date for due date and assigndate
}
//allows user to
Assignment::Assignment(string due, string descrip, string assigned, string status)
{
Description = descrip;
AssignmentStatus = makeStatus(status);//look into doing this having had a string passed in
//possible error handling?
try
{
DueDate = Date(due, US);//need to
}
catch(const exception&){
throw std::exception(" Due Date was not valid");
}
try
{
AssignDate = Date(assigned,US);
}
catch(const exception&)
{
throw std::exception(" Assigned Date was not valid");
}
if(!DatesValid())
throw std::exception("Due date must be after Assign date");
}
//copy constructor
Assignment::Assignment(const Assignment& original)
{
Description = original.Description;
AssignDate = original.AssignDate; //uses operator = as overloaded in Date class
DueDate = original.DueDate; //uses operator = as overloaded in Date class
AssignStatus AssignmentStatus = original.AssignmentStatus;
}
//returns a const string of the value for Description
const string Assignment::getDescription()
{
return Description;
}
//returns a const string of the value for AssignDate
const string Assignment::GetAssignDate()
{
return AssignDate.toString();//make sure this works to return date as a string
}
//returns a const string of the value for DueDate
const string Assignment::GetdueDate()
{
return DueDate.toString();//make sure this will return a string
}
//returns the value of AssignmentStatus
AssignStatus Assignment::getStatus()
{
return AssignmentStatus;// does not return a string, need to decide what to do about it
}
//returns string value of AssignmentStatus
const string Assignment::getStringStatus()
{
switch(AssignmentStatus)
{
default:
return "Status Error"; // need to think of a dbetter default
case AssignStatus::Assigned:
return "Assigned";
case AssignStatus::Complete:
return "Complete";
case AssignStatus::Late:
return "Late";
}
}
//changes AssignmentStatus to Late or Complete based on passed in Date
void Assignment::completeAssignment(Date completeDate)
{
//will add date validation for complete date here
if(completeDate > DueDate)//checks if the completion date was past the due date
{
AssignmentStatus = AssignStatus::Late;//changes AssignmentStatus to late
}
else
{
AssignmentStatus = AssignStatus::Complete;//changes assignment status to complete
}
}
//changes value of Description to that of the passed in string
void Assignment::changeDescription(string newDescrip)
{
Description = newDescrip;
}
//changes the due date to the date value of the passed in string
void Assignment::changeDueDate(string newDueDate)
{
//add try catch block around this statement
DueDate = Date(newDueDate, US);//uses the built in parsing and date validation of the date class
}
//converts a string to a status
AssignStatus Assignment::makeStatus(string stringStatus)
{
//couldn't make switch work so made ugly if statements
if(stringStatus == "Assigned")
return AssignStatus::Assigned;
else if(stringStatus == "Complete")
return AssignStatus::Complete;
else if(stringStatus == "Late")
return AssignStatus::Late;
else
throw std::exception("Invalid Status");
}
//defines < operator for use in Assignment class to make ordering assignments easier
bool Assignment::operator <(const Assignment& other) const
{
return DueDate < other.DueDate;//uses the built in < operator in Date class to compare assignments for use in ordering them
}
//for use in making sure the Assignment is unique
bool Assignment::operator ==(const Assignment& other) const
{
return AssignDate == other.AssignDate;//uses operator == as overloaded in Date class
}
//private function to check if due date and assigndate are within valid parameters
bool Assignment::DatesValid()
{
if(DueDate <= AssignDate)//uses the operator <= as overloaded in Date class
return false;
else
return true;
}