-
Notifications
You must be signed in to change notification settings - Fork 0
/
TT.CPP
767 lines (734 loc) · 14.1 KB
/
TT.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<string.h>
#include<stdlib.h>
extern void change();
extern int PERIODS;
extern int DAYS;
extern int *m,*p;
extern void mouse(int *);
class teacher
{
public:
char name[10];
char sub_teaching[20][10];
int no_of_sub,no_of_class,no_of_assignment;
char class_teaching[15][10];
int time[10][7];
struct assignment
{
char Class[10];
char subj[10];
int no_of_period,m_alloted_per,n_alloted_per,alloted_per;
};
assignment a[25];
int tot_per,tot_allot;
teacher *next;
teacher();
void assign(char *STD,char *SUBJ,int p);
void get();
void display();
void disp_time();
int search(char *STD,char *SUBJ);
float prior_cal(int n,int period,int x,int y,int s_no,char ct);
void clear_assign(int n);
void modify();
friend int search_name(char* NAME);
};
class Class
{ public:
char name[10];
int r_subno,o_subno;
int periods_left;
struct r_subject
{
char topic[10];
int t_no;
int assign_no;
float prior;
char ct;
};
r_subject r_sub[20];
struct o_subject
{
char name[10],topic[15][10];
int n,t_no[15],assign_no[15];
float prior;
char ct;
int no_of_period;
};
o_subject o_sub[10];
int time[10][7];
Class *next;
Class();
int assign(int teach_count);
void display();
void get();
int max_prior(int a,int b);
int max_prior2(int a,int b);
void exchange(int t_no,int a,int b,int x,int k);
void make(int a,int b,int k);
void modify();
void disp_time();
void mark(int a,int b,int x,int k);
void demark(int a,int b);
void allot(int a,int b,int x,int k);
void deallot(int a,int b);
void sp_make(int k);
int check_allot(int a,int b,int c_no);
friend int overwrite(int c_no,int t_no,int a,int b);
};
int class_count=0,teach_count=0;
Class *c=NULL;
teacher *t=NULL;
Class &C(int n)
{
Class *ptr=c;
for(int i=0;i<n;i++)
ptr=ptr->next;
return *ptr;
}
teacher &T(int n)
{
teacher *ptr=t;
for(int i=0;i<n;i++)
ptr=ptr->next;
return *ptr;
}
void init_var()
{
fstream f2("per.dat",ios::in|ios::binary);
if(!f2)
{
clrscr();
gotoxy(5,16);
textcolor(RED);
cout<<"Please set the following ::\n"
<<"\n\t\tThe number of periods in a day\n"
<<" \n\t\tThe number of working days in a week....." ;
getch();
change();
}
f2.seekg(0);
f2>>PERIODS>>DAYS;
f2.close();
}
void remove_var()
{
for(int i=0;i<class_count;i++)
delete &C(i);
for(i=0;i<teach_count;i++)
delete &T(i);
}
void read_class(char *f_name)
{
for(int x=0;x<class_count;x++)
delete &C(x);
char f_name2[15];
strcpy(f_name2,f_name);
strcat(f_name2,".cls");
ifstream fin(f_name2,ios::in|ios::binary);
int i=0;
c=new Class;
Class *prev=c;
while(1)
{
fin.read((char *)&C(i),sizeof(Class));
if(!fin||prev==NULL||i>120)
{
prev->next=NULL;
break;
}
Class *newptr=new Class;
prev->next=newptr;
prev=newptr;
i++;
}
fin.close();
class_count=i;
}
void read_teach(char *f_name)
{
for(int x=0;x<teach_count;x++)
delete &T(x);
char f_name2[15];
strcpy(f_name2,f_name);
strcat(f_name2,".tch");
ifstream fin(f_name2,ios::in|ios::binary);
int i=0;
t=new teacher;
teacher *prev=t;
while(1)
{
fin.read((char *)&T(i),sizeof(teacher));
if(!fin||prev==NULL||i>120)
{
prev->next=NULL;
break;
}
teacher *newptr=new teacher;
prev->next=newptr;
prev=newptr;
i++;
}
fin.close();
teach_count=i;
}
void write_class(char *f_name)
{
char f_name2[15];
strcpy(f_name2,f_name);
strcat(f_name2,".cls");
ofstream fout(f_name2,ios::out|ios::binary);
for(int i=0;i<class_count;i++)
fout.write((char *)&C(i),sizeof(Class));
fout.close();
}
void write_teach(char *f_name)
{
char f_name2[15];
strcpy(f_name2,f_name);
strcat(f_name2,".tch");
ofstream fout(f_name2,ios::out|ios::binary);
for(int i=0;i<teach_count;i++)
fout.write((char *)&T(i),sizeof(teacher));
fout.close();
}
void assignment()
{
int opt,ch;
ofstream fout;
do
{
clrscr();
read_class("DEFAULT2");
gotoxy(10,4);
cprintf("Selected assignments will be deleted ... ");
clrscr();
if(class_count==0)
{
gotoxy(10,4);
cprintf("No classes have been assigned !!!... ");
read_teach("DEFAULT1");
write_teach("DEFAULT2");
}
gotoxy(32,2);
textcolor(4);
cprintf("OLD ASSIGNMENT");
gotoxy(32,3);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(35,4);
for(int i=0;i<class_count;i++)
{
gotoxy(20,wherey()+2);
cout<<C(i).name;
}
gotoxy(20,wherey()+2);
cprintf("Assign teachers to a new class");
gotoxy(20,wherey()+2);
cprintf("Back");
mouse(m);
opt=(m[2]-40)/16;
clrscr();
if(opt==class_count)
{
read_class("DEFAULT1");
do
{
gotoxy(35,4);
for(int i=0;i<class_count;i++)
{
gotoxy(20,wherey()+2);
cout<<C(i).name;
}
gotoxy(20,wherey()+2);
cprintf("Back");
mouse(p);
ch=(p[2]-40)/16;
if(ch==class_count)
break;
else if(ch>=0&&ch<class_count)
{
clrscr();
gotoxy(35,4);
int verify=C(ch).assign(teach_count);
if(verify!=0)
{
fout.open("DEFAULT2.cls",ios::app|ios::binary);
fout.write((char*)&C(ch),sizeof(Class));
write_teach("DEFAULT2");
fout.close();
}
}
}while(ch<0||ch>class_count);
}
else if(opt>=0&&opt<class_count)
{
int verify=C(opt).assign(teach_count);
if(verify==1)
{
write_class("DEFAULT2");
write_teach("DEFAULT2");
}
if(verify==0)
{
write_teach("DEFAULT2");
fout.open("DEFAULT2.cls",ios::out|ios::binary);
for(int i=0;i<class_count;i++)
{
cout<<" F ";
if(i!=opt)
{ fout.write((char *)&C(i),sizeof(Class));
cout<<"S";
}
getch();
}
}
}
}while(opt!=class_count+1);
}
/*
void assignment()
{
int opt;
char ch;
ifstream file1;
ofstream file3;
ass1:
clrscr();
read_class("DEFAULT2");
read_teach("DEFAULT2");
gotoxy(10,4);
cprintf("Selected assignments will be deleted ... ");
if(class_count==0)
{
gotoxy(10,4);
cprintf("No classes have been assigned !!!... ");
read_teach("DEFAULT1");
write_teach("DEFAULT2");
}
do
{
gotoxy(32,2);
textcolor(4);
cprintf("OLD ASSIGNMENT");
gotoxy(32,3);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(35,4);
for(int i=0;i<class_count;i++)
{
gotoxy(20,wherey()+2);
cout<<C(i).name;
}
gotoxy(20,wherey()+2);
cprintf("Proceed to New Assignment");
mouse(m);
opt=(m[2]-24)/16;
}while(opt<1||opt>(class_count+1));
if(opt<=class_count)
{
file3.open("temp",ios::out|ios::binary);
for(int i=0;i<class_count;i++)
{
if(i!=opt-1)
file3.write((char *)&C(i),sizeof(Class));
else
{
clrscr();
C(i).display();
gotoxy(10,wherey()+5);
cprintf("Do you want to Delete This ? :: ");
cin>>ch;
if(ch!='y'&&ch!='Y')
file3.write((char *)&C(i),sizeof(Class));
}
}
file3.close();
remove("DEFAULT2.cls");
rename("temp","DEFAULT2.cls");
int x,n;
if(ch=='y'||ch=='Y')
{
for(i=0;i<C(opt-1).r_subno;i++)
{
x=C(opt-1).r_sub[i].t_no;
n=C(opt-1).r_sub[i].assign_no;
T(x).clear_assign(n);
}
for(i=0;i<C(opt-1).o_subno;i++)
{
for(int j=0;j<C(opt-1).o_sub[i].n;++j)
{
x=C(opt-1).o_sub[i].t_no[j];
n=C(opt-1).o_sub[i].assign_no[j];
T(x).clear_assign(n);
}
}
}
}
if(opt!=class_count+1)
goto ass1;
ass2:
clrscr();
read_class("DEFAULT1");
file3.open("DEFAULT2.cls",ios::app|ios::binary);
gotoxy(10,24);
cprintf("The following assignments will be appended ....");delay(1000);
clrscr();
do
{
gotoxy(32,2);
textcolor(4);
cprintf("NEW ASSIGNMENT");
gotoxy(32,3);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(35,4);
for(int i=0;i<class_count;i++)
{
gotoxy(20,wherey()+2);
cout<<C(i).name;
}
gotoxy(20,wherey()+2);
cprintf("Back");
mouse(m);
opt=(m[2]-24)/16;
}while(opt<1||opt>(class_count+1));
if(opt<=class_count)
{
clrscr();
gotoxy(35,4);
int verify=C(opt-1).assign(teach_count);
if(verify!=0)
file3.write((char*)&C(opt-1),sizeof(Class));
gotoxy(10,wherey()+2);
cprintf("Do you want to Assign Teachers to another Class ? :: ");
ch=getch();
file3.close();
if(ch=='y'||ch=='Y')
goto ass2;
else
write_teach("DEFAULT2");
}
else
if(opt!=class_count+1)
goto ass2;
}
*/
void viewtime()
{
int ch1=0,ch2;
while(ch1!=3)
{
clrscr();
gotoxy(35,18);
textcolor(4);
cprintf("TIME TABLE");
gotoxy(35,19);
cprintf("ÍÍÍÍÍÍÍÍÍÍ");
gotoxy(30,22);
textcolor(10);
cprintf("Class wise ");
gotoxy(30,24);
cprintf("Teacher wise ");
gotoxy(30,26);
cprintf("Back");
mouse(m);
ch1=(m[2]/16)-9;
switch(ch1)
{
case 1: while(1)
{
clrscr();
gotoxy(35,2);
textcolor(4);
cprintf("CLASS MENU");
gotoxy(35,3);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(35,4);
if(class_count==0)
{
gotoxy(10,4);
cprintf("There are no classes to display");
}
for(int i=0;i<class_count;i++)
{
gotoxy(20,wherey()+1);
cout<<C(i).name;
}
gotoxy(20,wherey()+1);
cprintf("Back");
mouse(m);
ch2=(m[2]/8)-3;
if(ch2==class_count+1)
break;
else
if(ch2>class_count+1||ch2<1)
continue;
C(ch2-1).disp_time();
mouse(p);
}
break;
case 2: while(1)
{
clrscr();
gotoxy(35,2);
textcolor(4);
cprintf("TEACHER MENU");
gotoxy(35,3);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(10,4);
if(teach_count==0)
{
gotoxy(10,4);
cprintf("There are no teachers to display");
gotoxy(10,4);
}
for(int i=0;i<teach_count;i++)
{
if(i<=39)
{
gotoxy(10,wherey()+1);
cout<<T(i).name;
if(i==39)gotoxy(30,4);
}
else if(i<=79)
{
gotoxy(30,wherey()+1);
cout<<T(i).name;
if(i==79)gotoxy(50,4);
}
else if(i<=119)
{
gotoxy(50,wherey()+1);
cout<<T(i).name;
}
}
if(wherex()>=30)
if(wherex()>=50)
gotoxy(50,wherey()+1);
else
gotoxy(30,wherey()+1);
else
gotoxy(10,wherey()+1);
cprintf("Back");
m[2]=0;mouse(m);
if(m[1]/8>49)
ch2=((m[2]/8)+80-3);
else if(m[1]/8>29)
ch2=((m[2]/8)+40-3);
else
ch2=(m[2]/8)-3;
if(ch2==teach_count+1)
break;
else
if(ch2>teach_count+1||ch2<1)
continue;
T(ch2-1).disp_time();
}
break;
}
}
}
void manual()
{
clrscr();
int opt;
do
{
clrscr();
gotoxy(35,2);
textcolor(4);
cprintf("MANUAL EDIT");
gotoxy(35,3);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(35,4);
if(class_count==0)
{
gotoxy(10,4);
cprintf("There are no classes to display");
}
for(int i=0;i<class_count;i++)
{
gotoxy(20,wherey()+2);
cout<<C(i).name;
}
gotoxy(20,wherey()+2);
cprintf("Next");
gotoxy(20,wherey()+2);
cprintf("Back");
mouse(m);
opt=(m[2]-24)/16;
if(opt<=class_count)
{
C(opt-1).sp_make(opt-1);
}
else if(opt==class_count+1)
{
clrscr();
gotoxy(20,20);
char f_name[15];
gotoxy(10,wherey()+4);
cprintf("Do you want to save this time table ?");
gotoxy(30,wherey()+2);
cprintf("Yes");
gotoxy(50,wherey());
cprintf("No");
do
{
p[1]=0;p[2]=0;mouse(p);
if(p[1]/8<49&&p[2]/8==wherey()-1)
{
gotoxy(25,wherey()+2);
cprintf("Enter File Name :: " );
gets(f_name);
write_class(f_name);
write_teach(f_name);
gotoxy(40,wherey()+2);
cprintf("SAVING COMPLETE ");
mouse(p);
break;
}
}while(!(p[1]/8>=49&&p[2]/8==wherey()-1));
for(int j=1;j<=DAYS;j++)
for(int i=1;i<=PERIODS;i++)
for(int k=0;k<class_count;k++)
C(k).make(i,j,k);
cout<<"Generation of timetable complete";getch();
viewtime();
clrscr();
gotoxy(20,20);
gotoxy(10,wherey()+4);
cprintf("Do you want to save this time table ?");
gotoxy(30,wherey()+2);
cprintf("Yes");
gotoxy(50,wherey());
cprintf("No");
do
{
p[1]=0;p[2]=0;mouse(p);
if(p[1]/8<49&&p[2]/8==wherey()-1)
{
gotoxy(25,wherey()+2);
cprintf("Enter File Name :: " );
gets(f_name);
write_class(f_name);
write_teach(f_name);
gotoxy(40,wherey()+2);
cprintf("SAVING COMPLETE ");
mouse(p);
break;
}
}while(!(p[1]/8>=49&&p[2]/8==wherey()-1));
}
}while(opt!=class_count+1&&opt!=class_count+2);
}
void load()
{
int opt;
do
{
clrscr();
gotoxy(33,18);
textcolor(4);
cprintf("LOADED TIMETABLE");
gotoxy(33,19);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(30,22);
cprintf("View");
gotoxy(30,24);
cprintf("Edit");
gotoxy(30,26);
cprintf("Back");
mouse(m);
opt=(m[2]/16)-9;
switch(opt)
{
case 1: viewtime();
break;
case 2: manual();
break;
}
}while(opt!=3);
}
void tt()
{
randomize();
int ch;
do
{
clrscr();
gotoxy(31,16);
textcolor(4);
cprintf("TIME TABLE CREATOR");
gotoxy(31,17);
cprintf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
textcolor(10);
gotoxy(20,20);
cprintf("Assign teachers");
gotoxy(20,22);
cprintf("Make a new time table");
gotoxy(20,24);
cprintf("Load existing time table ");
gotoxy(20,26);
cprintf("Delete existing time table");
gotoxy(20,28);
cprintf("Back");
mouse(m);
ch=(m[2]/16)-8;
switch(ch)
{
case 1: ifstream fin("DEFAULT2.tch");
if(!fin)
{
read_teach("DEFAULT1");
write_teach("DEFAULT2");
}
fin.close();
assignment();
break;
case 2:
read_class("DEFAULT2");
read_teach("DEFAULT2");
manual();
break;
case 3:{
char f_name[15];
clrscr();
gotoxy(20,25);
cprintf("Enter the File Name :: ");
gets(f_name);
read_class(f_name);
read_teach(f_name);
load();
break;
}
case 4:{
char f_name1[15],f_name2[15];
clrscr();
gotoxy(10,24);
cprintf("Enter File Name to be Deleted :: ");
char F_NAME[15];
gets(F_NAME);
strcpy(f_name1,F_NAME);
strcpy(f_name2,f_name1);
strcat(f_name2,".cls");
strcat(f_name1,".tch");
remove(f_name1);
remove(f_name2);
cout<<"\n\n\t\t"<<F_NAME<<" deleted";
delay(1000);
break;
}
case 5: break;
}
}while(ch!=5);
}