-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoach.h
157 lines (125 loc) · 6.1 KB
/
Coach.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
//Julian Worn
//07/17/2023
//Coach.h
//Header file for the Coach class in the scheduling system
#include <iostream>
#include <queue>
#include <fstream>
#include "Node.h"
#ifndef Coach_H
#define Coach_H
using namespace std;
/*
Class Invariant:
- only players that got "prioritized" within the addPlayer() function will be included in the schedule
- players will be added to newPlayers first, waiting to be rated
- you can only make a schedule after providing workHours for the coach
- the workSchedule needs to be a pointer to a 2d array of 7x24 to resemble the hours in a week, 0 means no time,
1 means available, <name> means player with name <name> scheduled, nullptr for a day means no availability at all for that day
- deep copying, and move semantics supported
- the scheduling will schedule as many lessons as possible, finishing off people from the highest priority before moving on,
same priority means first come first serve in regards of signing up for lessons
-operator overloading provided as adding feature when adding Player to Coach (C=C+P , C=P+C , C+=P)
*/
class Coach{
string name = "";
bool scheduleUpdated = false;
string** workSchedule = nullptr;
queue< shared_ptr<Player> > newPlayers;
shared_ptr<Node> allPlayers = nullptr;
//preconditions: parameter
//postconditions: deep copying happens here
void copy(const Coach& source);
//preconditions: parameter
//postconditions: recursively deep copies linked list and returns pointer to head
shared_ptr<Node> copyList(shared_ptr<Node> iter);
public:
//preconditions: parameters must be provided
//postconditions: constructing object with given name and empty queue and nullptrs for players and workSchedule
Coach(string n);
//preconditions: parameters must be provided
//postconditions: instance of coach created with passed workSchedule.
//ownership assumed, pointer of parameter set to null, if parameter of array is nullptr,
//interpreted as no availability at all
Coach(string n, string**& hours);
//deep copying supported for copy constructor
Coach(const Coach& source);
//move constructor
//preconditions: -
//postconditions: leaves parameter object in invalid state
Coach(Coach&& source);
//deep copying supported for assignment operator
void operator=(const Coach& source);
//move assignment operator
//preconditions: -
//postconditions: leaves parameter object in unknown state
void operator=(Coach&& source);
//customized destructor
//deallocates array and sets reference count of shared pointer handles to 0 to be deallocated immediately
~Coach();
//preconditions: parameters must be provided
//postconditions: ownership assumed, pointer of parameter set to null, if parameter of array is nullptr,
//interpreted as no availability at all, work schedule changed to new array
void setHours(string**& workHours);
//preconditions: -
//postconditions: newPlayers queue empty, players get rated in priority and added to allPlayers
//scheduleUpdated is false
void rateNewPlayers();
//preconditions: parameters must be provided
//postconditions: new player gets added to newPlayers queue (no priority specified yet, won't be included in schedule)
void addToNewPlayer(shared_ptr<Player> p);
//preconditions: parameters must be provided
//postconditions: new player gets rated and added to linked list of AllPlayers
//scheduleUpdated false
void addPlayer(shared_ptr<Player>& p);
//preconditions: -
//postconditions: creates schedule based on workHours and listed Players in allPlayers. Coaches and Players arrays get updated
//scheduleUpdated true
void makeSchedule();
//preconditions: -
//postconditions: prints schedule and list of players who's wish is not satisfied
void printSchedule();
//preconditions: -
//postconditions: returns bool, true if there are no new players
bool getNoNewPlayers();
//preconditions: -
//postconditions: prints allPlayers list (rated players)
void printRatedPlayers();
//preconditions: -
//postconditions: returns bool state, true if the schedule was updated
bool getScheduleUpdated();
//preconditions: -
//postconditions: returns bool true, if the name exists already in the players list
bool nameExists(string n);
//preconditions: -
//postconditions: creates a cfv file in the current directory of the current schedule
void createFile();
//+ operator for mixed type addition
//precondition:
//postcondition: p gets added to current coach's allPlayer list, priority will be asked for
Coach operator+(const Player& p) const;
//+= operator for mixed type addition
//precondition:
//postcondition: p gets added to current coach's allPlayer list, priority will be asked for
Coach& operator+=(const Player& p);
};
//callback function to support all + operations for mixed types
//precondition:
//postcondition: p gets added to c allPLayer list, priority will be asked for
Coach operator+(const Player& p, const Coach& c);
#endif
/*
Implementation Invariant:
-class members are encapsulated with getters and setters being provided if necessary
-deep copying as well as move semantics are supported
-workSchedule is received through dependency injection and ownership is assumed
-the workSchedule stores the availabity as well as it gets updated when you schedule practice lessons
(0 means no time, 1 means time, any name means this person has practice then,
nullptr means that the coach is not available on that day)
-operator overloading provided as adding feature when adding Player to Coach
-newPlayers is implemented as a queue to add in Players as received by time
-allPlayers is a priority queue, implemented as linked list that adds Players sorted by priority and time
I picked this priority queue implementation because the adding of the player happens over multiple weeks so
O(n) is negligible, but makeSchedule function can interate through the list and retrieve the highest priority from the
start till end with O(n) instead of O(log n * n) for example (heap implementation)
*/