This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eurovision.h
268 lines (249 loc) · 7.53 KB
/
eurovision.h
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
#ifndef EUROVISION_H_
#define EUROVISION_H_
#include <iostream>
#include <string>
#include <vector>
// it's allowed to define here any using statements, according to needs.
// do NOT define here : using namespace std;
using std::string;
using std::vector;
using std::ostream;
using std::endl;
//---------------------------------------------------
enum VoterType { All, Regular, Judge };
enum Phase { Registration, Contest, Voting };
enum Direction { Left, Right };
//---------------------------------------------------
/**
* contains Participant attributes and methods as described in the PDF
*/
class Participant
{
const string state_name;
string song_name;
int song_length;
string singer_name;
bool is_registered;
public:
Participant(string state, string song,
int timeLength, string singer);
~Participant() = default;
Participant(const Participant& p) = delete;
Participant &operator=(const Participant& p) = delete;
/**
* @return state_name
*/
const string state() const;
/**
* @return state_name
*/
string song() const;
/**
* @return song_name
*/
int timeLength() const;
/**
* @return song_length
*/
string singer() const;
/**
* @return is_registered
*/
bool isRegistered() const;
/**
* update the attributes of song_name, song_length and singer_name
* @param song
* @param timeLength
* @param singer
*/
void update(string song, int timeLength, string singer);
/**
* update the is_registered attribute({True,False})
* @param flag
*/
void updateRegistered(bool flag);
};
//---------------------------------------------------
/**
* contains Voter attributes and methods as described in the PDF
*/
class Voter
{
const string state_name;
const VoterType type;
int times_voted;
public :
explicit Voter(string state, VoterType type = Regular);
Voter(const Voter& voter) = delete;
Voter &operator=(const Voter& voter) = delete;
~Voter() = default;
/**
* increments times_voted by 1
*/
Voter& operator++();
/**
* @return state_name
*/
const string state() const;
/**
* @return type
*/
VoterType voterType() const;
/**
* @return times_voted
*/
int timesOfVotes() const;
};
// -----------------------------------------------------------
/**
* contain reference to Voter, and array of state the voter voted to
* if voter is regular only the first state will get his vote
*/
struct Vote
{
Voter& voter;
string* states;
/**
* @param voter
* @param state0 - the only state in regular vote, and no.1 state in
* judge votes
* @param state1-9 - places 2-10 in judge votes
*/
Vote(Voter& voter, string state0,
string state1 = "", string state2 = "",
string state3 = "", string state4 = "",
string state5 = "", string state6 = "",
string state7 = "", string state8 = "",
string state9 = "");
Vote(const Vote& vote);
Vote &operator=(const Vote& vote) = delete;
~Vote();
};
// -----------------------------------------------------------
/**
* contains MainControl attributes and methods as described in the PDF
* contains the limit allowed in the eurovision, phase, array of
* ParticipantWithVotes that holds registered Participant to the eurovision.
* also contains Iterator, with the standard operators
*/
class MainControl
{
const int max_time_length;
const int max_number_of_participants;
const int max_times_voter;
Phase phase;
/**
* include a pointer to registered participant, sum of his regular votes,
* and sum of his judge votes
*/
struct ParticipantWithVotes{
Participant* participant;
int regular_votes;
int judge_votes;
explicit ParticipantWithVotes(Participant* participant= nullptr);
~ParticipantWithVotes() = default;
ParticipantWithVotes &operator=(const ParticipantWithVotes &pwv) = default;
ParticipantWithVotes(const ParticipantWithVotes &pwv) = default;
static void swap(ParticipantWithVotes& a, ParticipantWithVotes& b);
};
/**
* @param state name
* @return the index of the state in the participants array
*/
int get_state_index(const string& state) const;
/**
* shifts the participants array left of right
* for example
* {*,*,*,NULL,*,*} shifting this array left with
* index 3 will do{*,*,*,*,*,*,NULL}
* @param i
* @param d
*/
void shift(int i, Direction d);
/**
* array of all registered participants
*/
ParticipantWithVotes* participant_array;
int participant_counter;
/**
* @param state
* @return pointer to participant with votes in the participants array
*/
ParticipantWithVotes* getByState(string state) const;
public :
explicit MainControl(int max_time_length = 180,
int max_number_of_participants = 26,
int max_times_voter = 5);
MainControl(const MainControl &contest) = delete;
MainControl &operator=(const MainControl &contest) = delete;
~MainControl();
/**
* setting the phase in the conditions as described in the PDF
* @param new_phase
*/
void setPhase(Phase new_phase);
/**
* @param participant_name
* @return if the participant is registered
*/
bool participate(string participant_name);
/**
* @param p
* @return if the participant is can be registered
*/
bool legalParticipant(Participant& p);
/**
* register a participant to the contest
* @param p
*/
MainControl &operator+=(Participant& p);
/**
* unregister a participant to the contest
* @param p
*/
MainControl &operator-=(Participant& p);
/**
* adding vote to participant
* @param vote
*/
MainControl &operator+=(Vote vote);
friend ostream &operator<<(ostream &os, const MainControl &mc);
class Iterator{
int i;
ParticipantWithVotes* participant_arr;
public:
Iterator(int init = 0, ParticipantWithVotes* pwd = nullptr);
~Iterator()= default;
Iterator &operator=(const Iterator &iterator) = default;
Iterator& operator++();
Participant& operator*() const;
bool operator==(const Iterator &iterator) const;
bool operator<(const Iterator &iterator) const;
};
Iterator begin() const;
Iterator end() const;
/**
* function like operator that returns the state that finish in the
* wanted location by the VoterType type.
* @param location
* @param type
*/
string operator()(int location, VoterType type);
};
ostream &operator<<(ostream &os, const Participant &p);
ostream &operator<<(ostream &os, const Voter &voter);
ostream &operator<<(ostream &os, const MainControl &mc);
// -----------------------------------------------------------
/**
* get Container and index and returns the location of the index for the i for
* the container data, using operator<
* @tparam Iterator
* @param i
* @param begin
* @param end
* @return
*/
template <class Iterator>
Iterator get(int i, Iterator begin, Iterator end);
// -----------------------------------------------------------
#endif