-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA5.cpp
374 lines (303 loc) · 8.59 KB
/
A5.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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#include<iostream>
#include<string>
#include<fstream>
#include"A5.h"
#include<windows.h>
#include <utility>
using namespace std;
template<class T1,class T2>
int searchArray(T1 key, T2* arr,int size) {
for (int i=0;i<size;i++) {
if (arr[i].email == key) {
return i;
}
}
return -99;
}
template<class T1>
void updateArray(T1* &arr,int &size) {
size++;
T1* bigArr = new T1[size];
for (int i=0;i<size-1;i++) {
bigArr[i] = arr[i];
}
arr = bigArr;
}
template<class T1>
void decreaseArray(T1* arr, int &size,int id) {
size--;
T1 *newArr = new T1[size];
int l=0;
for (int i=0;i<size+1;i++) {
if (i != id) {
newArr[l] = arr[i];
l++;
}
}
arr = newArr;
}
Customer::Customer() {
id=-99;
name="";
address="";
phone="";
email="";
subArr = nullptr;
}
Customer::Customer(const Customer &rhs) {
this->id = rhs.id;
this->name = rhs.name;
this->address = rhs.address;
this->phone = rhs.phone;
this->email = rhs.email;
NumOfSub=0;
}
Customer::Customer(int id,string name,string address,string phone,string email) {
this->id = id;
this->name = name;
this->address = address;
this->phone = phone;
this->email = email;
NumOfSub=0;
}
void Customer::createSubscription(Gym* gm) {
cout << "Select A Trainer through his id \n";
for (int i=0;i<(*gm).numOfTrainers;i++) {
cout << "[" << (*gm).trainerArr[i].id+1 << "]" << (*gm).trainerArr[i].name << endl;
}
int trainerId; cin >> trainerId;
cout << "The trainer info is " <<(*gm).trainerArr[trainerId-1].NumOfPlans << endl;
(*gm).trainerArr[trainerId-1].planArr[0].Print();
cout << "Select a Plan \n";
for (int i=0;i<(*gm).trainerArr[trainerId-1].NumOfPlans;i++){
(*gm).trainerArr[trainerId-1].planArr[i].Print();
}
int pID;cin >> pID;
NumOfSub++;
cout << "Enter the day of Joining. 1-30/31 : ";
int day;cin >>day;
cout << "Enter the month of Joining. 1-30/31 : ";
int month;cin >>month;
cout << "Enter the year of Joining. 1-30/31 : ";
int year;cin >>year;
DateTime dt(day,month,year,0,0);
Trainer * t = &(((*gm).trainerArr[trainerId]));
ExercisePlan* c = &((*gm).trainerArr[trainerId].planArr[pID]);
int n = NumOfSub;
Subscription obj(n,gm,dt, t,c);
//Subscription test(12,gm,dt,t,c);
//(int id,Gym* gym,DateTime d,Trainer* t,ExercisePlan *p)
//id//datetime//trainer//explan
}
void Customer :: Print(){
HANDLE console_color;
console_color = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(console_color, 7);
cout << "Customer ID : " << (this->id) << endl;
SetConsoleTextAttribute(console_color, 9);
cout << "Customer Name : " << this->name << endl;
SetConsoleTextAttribute(console_color, 11);
cout << "Address : " << this->address << endl;
SetConsoleTextAttribute(console_color, 12);
cout << "Phone : " << this->phone << endl;
SetConsoleTextAttribute(console_color, 13);
cout << "Email : " << this->email << endl;
//Subscription* subArr;
//int NumOfSub;
}
// Functions for Subscription
Subscription :: Subscription() {
id=-99;
gym = nullptr;
trainer = nullptr;
Plan = nullptr;
}
Subscription :: Subscription(int id,Gym* gym,DateTime d,Trainer* t,ExercisePlan *p) {
this->id = id;
this->gym = gym;
trainer = t;
Plan = p;
this->d = d;
}
//END
//END
//
ExercisePlan ::ExercisePlan() {
id=0;
exerciseArr = nullptr;
}
ExercisePlan ::ExercisePlan(int id,Equipment* arr,int size,int eSize) {
this->id=id;
exerciseArr = new pair<Equipment,int>[size];
numOfEquipments = size;
for (int i=0;i<size;i++) {
cout << "Select an equiment through its ID\n";
int eChoice;
for (int i=0;i<eSize;i++) {
cout << arr[i].id << ". " << arr[i].name << endl;
}
cin >> eChoice;
exerciseArr[i].first = arr[eChoice];
cout << "Enter the duration for the Equipment : " << arr[eChoice].name << endl;
cin >> exerciseArr[i].second;
}
}
void ExercisePlan:: Print() {
cout << "Plan ID : " << this->id;
cout << "Details : \n";
for (int i=0;i<numOfEquipments;i++) {
cout << "\t" << exerciseArr[i].first.name << exerciseArr[i].second << endl;
}
}
//END
// Function for DATETIME
DateTime::DateTime()
{
this->Day = 1;
this->Month = 1;
this->Year = 2001;
}
DateTime :: DateTime(int Day, int Month, int Year,int Hours=0, int Mins=0)
{
this->Day = Day;
this->Month = Month;
this->Year = Year;
this->Hours = Hours;
this->Mins = Mins;
}
// Functions for Trainer
Trainer::Trainer()
{
id=-99;
name="";
planArr=nullptr;
NumOfPlans=0;
}
Trainer :: Trainer(int id, string name, string email){
this-> id = id;
this-> name = name;
this-> email = email;
NumOfPlans=0;
planArr=nullptr;
}
Trainer :: Trainer(const Trainer &rhs){
this->id = rhs.id;
this->name = rhs.name;
}
void Trainer::createPlan(Equipment* &obj,int eSize) {
int ID;
cout << "Enter the Plan ID" << endl;
cin >> ID;
cout << "Enter the number of exercises in this plan : ";
int size; cin >> size;
ExercisePlan EX(ID,obj,size,eSize);
NumOfPlans++;
//Include plan in planArr
ExercisePlan *temp = new ExercisePlan[NumOfPlans];
for (int i =0 ; i < NumOfPlans-1; i++) {
temp[i] = planArr[i];
}
temp[NumOfPlans-1] = EX;
//delete[]
planArr = temp;
}
void Trainer :: Print(){
HANDLE console_color;
console_color = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(console_color, 6);
cout << "Trainer Name : " << this->name << endl;
SetConsoleTextAttribute(console_color, 5);
cout << "Trainer ID : " << (this->id) << endl;
SetConsoleTextAttribute(console_color, 4);
cout << "Number Of Plans : " << this->NumOfPlans << endl;
SetConsoleTextAttribute(console_color, 3);
cout << "Plans : " << endl;
for (int i=0; i<NumOfPlans; i++)
{
planArr[i].Print();
cout << endl;
}
}
// END
// Functions for GYM
Gym :: Gym(int id,string name,Equipment* eq,int numOfEquipments){
this->id = id;
this->name = name;
this->numOfEquipments = numOfEquipments;
eqArr = new Equipment[numOfEquipments];
for (int i=0;i<numOfEquipments;i++) {
eqArr[i] = eq[i];
}
numOfTrainers=0;
}
void Gym::DeleteCustomer(){
for (int i=0; i<numOfCustomers; i++){
customerArr[i].Print(); cout << endl;
}
int index;
int choice;
cout << "Enter ID to delete\n"; cin >> choice;
index = searchArray(customerArr[choice].email,customerArr,numOfCustomers);
if (index != -99)
{
decreaseArray(customerArr,numOfCustomers,choice);
cout << "Deleted Successfully\n";
}
else
{ cout << "Not Found :(\n";}
}
void Gym::receiveCustomer(Customer &obj){
updateArray(customerArr,numOfCustomers);
customerArr[numOfCustomers-1] = obj;
// delete [] customerArr;
}
void Gym::receiveTrainer(Trainer &obj){
updateArray(trainerArr,numOfTrainers);
trainerArr[numOfTrainers-1] = obj;
// delete [] trainerArr;
}
void Gym :: Print(){
HANDLE console_color;
console_color = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(console_color, 3);
cout << "ID : " << this->id << endl;
SetConsoleTextAttribute(console_color, 12);
cout << "Name : " << this->name << endl;
SetConsoleTextAttribute(console_color, 13);
cout << "Num of Customers : " << numOfCustomers << endl;
SetConsoleTextAttribute(console_color, 14);
cout << "Customer Details : \n";
SetConsoleTextAttribute(console_color, 2);
for (int i = 0; i < numOfCustomers; i++)
{
cout << customerArr[i].name << endl;
cout << customerArr[i].id << endl;
}
cout << endl;
SetConsoleTextAttribute(console_color, 4);
cout << "Num of Trainers : " << numOfTrainers << endl;
SetConsoleTextAttribute(console_color, 3);
cout << "Trainer Details : \n";
SetConsoleTextAttribute(console_color, 6);
for (int i = 0; i < numOfTrainers; i++) {
cout << trainerArr[i].id << ". " <<trainerArr[i].name << endl;
}
}
// END
// end
Equipment :: Equipment() {
id=-99;
name = "";
}
Equipment:: Equipment(int id, string name) {
this->id = id;
this->name = name;
}
Gym:: Gym() {
id=-99;
name = "";
customerArr = nullptr;
trainerArr = nullptr;
eqArr = nullptr;
numOfTrainers=0;
}