-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchoolActivityManager.cpp
387 lines (373 loc) · 9.42 KB
/
SchoolActivityManager.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
375
376
377
378
379
380
381
382
383
384
385
386
387
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <fstream.h>
class act
{
char act_name[30];
char act_location[30];
char teacher_name[30];
char stu_name[30];
char month[30];
int day;
public:
char *aname()
{
return act_name;
}
void act_getdata()
{
cout << "Enter activity name : ";
gets(act_name);
cout << "Enter activity location : ";
gets(act_location);
cout << "Enter name of teacher in charge : ";
gets(teacher_name);
cout << "Enter name of student in charge : ";
gets(stu_name);
cout << "Enter date of activity :\n Enter month : ";
gets(month);
cout << " Enter day : ";
cin >> day;
}
void act_putdata()
{
cout << "\nActivity name : " << act_name;
cout << "\nActivity location : " << act_location;
cout << "\nName of teacher in charge : " << teacher_name;
cout << "\nName of student in charge : " << stu_name;
cout << "\nDate of activity :\n Month : " << month;
cout << " Day : " << day;
}
} act_obj;
void act_add();
void act_del();
void act_search();
void act_display();
void act_modify();
int actnamecheck(char str[]);
void res_add();
void res_display();
struct res
{
char act_name[30];
char res_name[30];
int res_amt;
int res_budget;
};
class resources
{
int r;
res reso[30];
public:
void res_getdata()
{
char warnch;
r = 0;
int check;
char morech;
again:
cout << "Enter activity name : ";
gets(reso[r].act_name);
check = actnamecheck(reso[r].act_name);
if (check == 1)
goto data;
if (check != 1)
{
cout << "\nWarning : You have entered an activity name that has no reccord !\n Do you want to continue (Y) or enter again (A) ? : ";
cin >> warnch;
if (warnch == 'y' || warnch == 'Y')
goto data;
else
goto again;
}
else
goto again;
data:
cout << "Enter budget for activity : ";
cin >> reso[r].res_budget;
do
{
cout << "Enter resource name : ";
gets(reso[r].res_name);
cout << "Enter resource amount : ";
cin >> reso[r].res_amt;
cout << "Enter more resources for the activity (Y/N)? ";
cin >> morech;
r++;
} while (morech == 'y' || morech == 'Y');
}
void res_putdata()
{
int re = 0;
;
cout << "Activity name : " << reso[re].act_name << endl;
cout << "Activity budget : " << reso[re].res_budget << endl;
for (re = 0; re <= r - 1; re++)
{
cout << "Resource name : " << reso[re].res_name << endl;
cout << "Resource amount : " << reso[re].res_amt << endl;
}
}
} res_obj;
void main()
{
int ch;
int input;
char inputch;
char password[30];
cout << "\n\t ***** WELCOME TO SCHOOL ACTIVITY MANAGER CONSOLE *****\n";
do
{
re:
cout << "\nMain Menu\n";
cout << "\n Choose account to login :\n";
cout << "\n 1. Teacher login\n 2. Admin login\n 3. Exit\n";
cin >> input;
if (input == 1)
{
cout << "\nEnter password\n";
gets(password);
if (strcmp(password, "@T101") == 0)
{
cout << "\nLogged in\n";
do
{
actmenu:
cout << "\nActivity Menu\n";
cout << "\nChoose an option (1-6)\n";
cout << "\n1. Enter new activity details\n2. Delete an activity\n3. Search an activity\n4. Modify activity details\n5. Display details of all activities\n6. Log out\n";
cin >> ch;
if (ch == 1)
act_add();
if (ch == 2)
act_del();
if (ch == 3)
act_search();
if (ch == 4)
act_modify();
if (ch == 5)
act_display();
if (ch == 6)
break;
} while (ch != 6);
}
else
{
cout << "\nWrong password !\n";
goto re;
}
}
else if (input == 2)
{
int ch1;
cout << "\nEnter password : ";
gets(password);
if (strcmp(password, "@A909") == 0)
{
cout << "\nLogged in\n";
do
{
remenu:
cout << "\nResource Menu\n";
cout << "\nChoose an option (1-3)\n";
cout << "\n1. Add resource(s) for an activity\n2. Display resource details of all activities\n3. Log out\n";
cin >> ch1;
if (ch1 == 1)
res_add();
if (ch1 == 2)
res_display();
if (ch1 == 3)
break;
} while (ch1 != 3);
}
else
{
cout << "\nWrong password !\n";
goto re;
}
}
if (input == 3)
{
cout << "\n\t ***** THANK YOU FOR USING SCHOOL ACTIVITY MANAGER CONSOLE *****\n";
break;
}
if (input != 1 && input != 2 && input != 3)
{
cout << "\nWrong choice\n";
goto re;
}
cout << "\nAre you sure you want to log out ? Y / N : ";
cin >> inputch;
if (inputch == 'n' || inputch == 'N')
{
if (input == 1)
goto actmenu;
if (input == 2)
goto remenu;
}
} while (inputch == 'y' || inputch == 'Y');
getch();
}
void act_add()
{
ofstream fout;
fout.open("act.dat", ios::app);
act_obj.act_getdata();
fout.write((char *)&act_obj, sizeof(act));
fout.close();
cout << "\nNew activity added\n";
}
void act_display()
{
int flag = 0;
ifstream fin;
fin.open("act.dat", ios::in);
while (!fin.eof())
{
fin.read((char *)&act_obj, sizeof(act));
if (fin.eof() && flag == 0)
{
cout << "\nNo activity data exists\n";
break;
}
if (fin.eof())
break;
act_obj.act_putdata();
flag++;
}
fin.close();
getch();
}
void act_search()
{
char ana[30];
int flag = 0;
cout << "\nEnter activity name to be searched ";
gets(ana);
ifstream fin;
fin.open("act.dat");
do
{
fin.read((char *)&act_obj, sizeof(act));
if (strcmpi(act_obj.aname(), ana) == 0)
{
flag = 1;
break;
}
} while (!fin.eof());
if (flag == 1)
{
cout << "\nActivity found\n";
act_obj.act_putdata();
}
if (flag == 0)
{
cout << "Not found";
}
fin.close();
getch();
}
void act_modify()
{
char ana[30];
cout << "\nEnter activity name to be modfied ";
gets(ana);
fstream fio;
fio.open("act.dat", ios::in | ios::out);
while (fio.read((char *)&act_obj, sizeof(act_obj)))
{
int pos = fio.tellg();
fio.read((char *)&act_obj, sizeof(act_obj));
if (strcmpi(act_obj.aname(), ana) == 0)
{
cout << "\nEnter new activity details\n";
act_obj.act_getdata();
fio.seekg(pos);
fio.write((char *)&act_obj, sizeof(act_obj));
cout << "Records updated\n";
}
}
getch();
}
void act_del()
{
ifstream fin;
ofstream fout;
fin.open("act.dat", ios::nocreate);
fout.open("file.dat", ios::out);
char ana[30];
cout << "Enter the activity name of the record you wish to delete\n";
gets(ana);
while (fin.read((char *)&act_obj, sizeof(act)))
{
fin.read((char *)&act_obj, sizeof(act));
if (fin.eof())
break;
if (strcmpi(act_obj.aname(), ana) == 1)
{
fout.write((char *)&act_obj, sizeof(act));
}
}
fin.close();
fout.close();
remove("act.dat");
rename("file.dat", "act.dat");
cout << "Records updated\n";
}
void res_add()
{
ofstream fout;
fout.open("res.dat", ios::app);
res_obj.res_getdata();
fout.write((char *)&res_obj, sizeof(resources));
fout.close();
cout << "\nNew resources added\n";
}
void res_display()
{
int flag = 0;
ifstream fin;
fin.open("res.dat", ios::in);
while (!fin.eof())
{
fin.read((char *)&res_obj, sizeof(resources));
if (fin.eof() && flag == 0)
{
cout << "\nNo resource data exists\n";
break;
}
if (fin.eof())
break;
res_obj.res_putdata();
flag++;
}
fin.close();
getch();
}
int actnamecheck(char ana[])
{
int flag = 0;
ifstream fin;
fin.open("act.dat");
do
{
fin.read((char *)&act_obj, sizeof(act));
if (strcmpi(act_obj.aname(), ana) == 0)
{
flag = 1;
break;
}
} while (!fin.eof());
fin.close();
if (flag == 1)
{
cout << "\nActivity found\n";
return 1;
}
else
{
cout << "\nActvity not found";
return 0;
}
}