-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_event.cpp
84 lines (75 loc) · 1.82 KB
/
base_event.cpp
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
#include "base_event.h"
using std::string;
using std::ostream;
using std::endl;
using mtm::BaseEvent;
using mtm::DateWrap;
using mtm::AlreadyRegistered;
using mtm::InvalidStudent;
BaseEvent::BaseEvent(const mtm::DateWrap& date, const std::string& name)
:name(name), date(date), participants(){}
void BaseEvent::registerParticipant(int participant)
{
if (participant > this->MAX_STUDENT || participant < this->MIN_STUDENT)
{
throw InvalidStudent();
}
if (this->participants.contains(participant))
{
throw AlreadyRegistered();
}
participants.add(participant);
}
void BaseEvent::unregisterParticipant(int participant)
{
if (participant > this->MAX_STUDENT || participant < this->MIN_STUDENT)
{
throw InvalidStudent();
}
if(!this->participants.contains(participant))
{
throw NotRegistered();
}
participants.remove(participant);
}
ostream& BaseEvent::printShort(ostream& out) const
{
out << name << " " << date << endl;
return out;
}
ostream& BaseEvent::printLong(ostream& out) const
{
printShort(out);
List<int>::ListIterator current = participants.begin();
List<int>::ListIterator end = participants.end();
while(current != end)
{
out << *current << endl;
++current;
}
return out;
}
bool BaseEvent::operator<(const BaseEvent& event) const
{
if(this->date != event.date)
{
return this->date < event.date;
}
return(this->name < event.name);
}
bool BaseEvent::operator==(const BaseEvent& event) const
{
return (this->name == event.name) && (this->date == event.date);
}
mtm::DateWrap BaseEvent::getDate() const
{
return this->date;
}
std::string BaseEvent::getName() const
{
return this->name;
}
void BaseEvent::changeDate(int days_to_add)
{
this->date+=days_to_add;
}