-
Notifications
You must be signed in to change notification settings - Fork 99
/
test-prep.cpp
1095 lines (839 loc) · 33.1 KB
/
test-prep.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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <bits/stdc++.h>
using namespace std;
class topic
{
public:
string name;
int count=0;
int priority;
int difficulty;
double time;
int weightage;
int imp;
};
class subject
{
public:
string sname;
topic c[];
int credits;
int prep;
int prepp;
float stime;
int imp;
float profit;
int examdate;
int time_left;
int topics;
int diff;
float ttime;
float atime;
double lrate;
float pptime;
float rtime;
};
void printJobScheduling(subject arr[], int n);
double fractionalKnapsack(int W, topic arr[], int n);
bool cmp(topic a, topic b)
{
double r1 = (double)a.priority / a.time;
double r2 = (double)b.priority / b.time;
return r1 > r2;
}
bool cmpsub(subject a,subject b)
{
return (a.credits<b.credits);
}
bool cmpDate(subject s1,subject s2)
{
return s1.time_left<s2.time_left;
}
bool cmpDiff(topic a,topic b)
{
return (a.difficulty<b.difficulty);
}
bool cmpImp(topic a,topic b)
{
return (a.imp<b.imp);
}
bool comparison(subject a, subject b)
{
return (a.imp > b.imp);
}
void printJobScheduling(subject arr[], int n)
{
sort(arr, arr+n, comparison);
int result[n];
bool slot[n];
for (int i=0; i<n; i++)
slot[i] = false;
for (int i=0; i<n; i++)
{
for (int j=min(n, arr[i].time_left)-1; j>=0; j--)
{
if (slot[j]==false)
{
result[j] = i; // Add this job to result
slot[j] = true; // Make this slot occupied
break;
}
}
}
int k=1;
for (int i=n-1; i>=0; i--)
{
if(slot[i])
{
cout <<k<<". ";
cout << arr[result[i]].sname << "\n";
k++;
}
}
/* for (int i=n-1; i>=0; i++)
{
if (slot[i]){ cout <<i;
cout << arr[result[i]].sname << "\n";}
}*/
}
double fractionalKnapsack(float W, topic arr[], int n)
{
sort(arr, arr + n, cmp);
int curMarks = 0; // Current weight in knapsack
double finalvalue = 0.0; // Result (value in Knapsack)
for (int i = 0; i < n; i++)
{
if (curMarks + arr[i].time <= W)
{
curMarks += arr[i].time;
finalvalue += arr[i].weightage;
if(arr[i].count==0)
{
cout<<"\n--------------------------------"<<endl;
cout<<"For "<<arr[i].name<<": "<<endl;
}
if(arr[i].count==1)
{
float trev=arr[i].time/2;
float tpaper=arr[i].time/4;
float tdoubts=arr[i].time/4;
if(trev<1)
{
trev*=60;
tpaper*=60;
tdoubts*=60;
//cout<<"\n------------------------------------------------------"<<endl;
cout<<"You can revise the topic "<<arr[i].name<< " in "<<trev<<" minutes"<<endl;
//cout<<"\n-----------------------------------------------------------------------------------------------"<<endl;
cout<<"Do not forget to take a look at last year questions for this topic in the next "<<tpaper<<" minutes"<<endl;
//cout<<"\n------------------------------------------------------------------------------------"<<endl;
cout<<"Try to clear your doubts about this topic in the next "<<tdoubts<<" minutes"<<"\n"<<endl;
}
else if((tpaper<1)&&(trev>=1))
{
tpaper*=60;
tdoubts*=60;
//cout<<"\n------------------------------------------------------"<<endl;
cout<<"You can revise the topic "<<arr[i].name<< " in "<<trev<<" hours"<<endl;
//cout<<"\n-----------------------------------------------------------------------------------------------"<<endl;
cout<<"Do not forget to take a look at last year questions for this topic in the next "<<tpaper<<" minutes"<<endl;
//cout<<"\n------------------------------------------------------------------------------------"<<endl;
cout<<"Try to clear your doubts about this topic in the next "<<tdoubts<<" minutes"<<"\n"<<endl;
}
else
{
//cout<<"\n------------------------------------------------------"<<endl;
cout<<"You can revise the topic "<<arr[i].name<< " in "<<trev<<" hours"<<endl;
//cout<<"\n-----------------------------------------------------------------------------------------------"<<endl;
cout<<"Do not forget to take a look at last year questions for this topic in the next "<<tpaper<<" hours"<<endl;
cout<<"\n------------------------------------------------------------------------------------"<<endl;
cout<<"Try to clear your doubts about this topic in the next "<<tdoubts<<" hours"<<"\n"<<endl;}
}
}
else
{
int remain = W - curMarks;
finalvalue += arr[i].weightage * ((double) remain / arr[i].time);
cout<<"You can only do some part of the chapter"<<endl;
break;
}
if(curMarks>=W){return 0.0;}
}
return finalvalue;
}
void user_feedback(){
int ratings;
cout<<"----------------------------------------------------------------------------------";
cout<<"\nPlease give us a feedback on the basis of the preparation schedule provided to you:\nRate us out of 5 where 1 symbolises lowest"<<endl;
cin>>ratings;
cout<<"______________"<<endl;
cout<<"|Thank You!:D|"<<endl;
cout<<"**************"<<endl;
}
/*
end
COMPLETE FOR 1 SUBJECT
*/
int main()
{
int option;
cout <<" ___________________________________________________________________________"<<endl;
cout <<" | WELCOME TO |"<<endl;
cout <<" | |"<<endl;
cout <<" | LEARNING MADE EASY |"<<endl;
cout <<" | |"<<endl;
cout <<" | MENU |"<<endl;
cout <<" | |"<<endl;
cout <<" | 1 to schedule a given subject in limited time |"<<endl;
cout <<" | 2 to schedule studies for all subjects for a long period of time |"<<endl;
cout <<" | 3 for mixed schedule of all subjects(if you have enough time) |"<<endl;
cout <<" | |"<<endl;
cout <<" | |"<<endl;
cout <<" |_________________________________________________________________________|"<<endl;
cout << "\nEnter your required option: ";
cin >> option;
if (option == 1)
{
int n;
cout << "---------------------------"<<endl;
cout << "Enter the no. of topics: ";
cin >> n;
int total_diff = 0; // sp
topic t[2 * n];
cout << "----------------------------"<<endl;
cout << "Enter name of each topic: "<<endl;
for (int i = 0; i < n; i++)
{
cout<< "Topic "<<i+1<<": ";
cin >> t[i].name;
}
cout << "----------------------------------------------------------";
cout << "\nEnter priority of each topic i.e. expected weightage: "<<endl;
cout << "'From 1-10_____1 being the easiest:' "<<endl;
for (int i = 0; i < n; i++)
{
cout <<"For " <<t[i].name << " : ";
cin >> t[i].priority;
t[i].weightage = t[i].priority;
t[i].count = 0;
}
cout << "-------------------------------------------------------"<<endl;
cout << "Enter difficulty level of each topic according to you"<<endl;
cout << "'From 1-10_____1 being the easiest:' "<<endl;
for (int i = 0; i < n; i++)
{
cout <<"For " <<t[i].name << " : ";
cin >> t[i].difficulty;
total_diff = total_diff + t[i].difficulty;
}
total_diff = total_diff + total_diff / 2;
cout<<endl;
int total_time; // tt
int focused_time; // eff
cout << "--------------------------------------------------------------"<<endl;
cout << "\nEnter total time available to study this subject in hours: ";
cin >> total_time;
cout << "\n-----------------------------------------------------------------------"<<endl;
cout << "How much you can resist yourself from using phone during exams?(1-10): ";
cin >> focused_time;
cout<<"\n";
float available_time = total_time * focused_time / 10; //at
cout << "---------------------------"<<endl;
cout << "Total Allotted time: " << available_time << "\n";
cout << "\nDifficulty Level: " << total_diff << "\n";
float utilised_val = available_time / total_diff; //ut
cout << "\nTime Utilization rate: " << utilised_val << "\n";
for (int i = 0; i < n; i++)
{
t[i].time = utilised_val * t[i].difficulty / 10;
//cout << t[i].name << " " << t[i].time * 10 << "\n";
}
int checksub;
// cout << "The time is: ";
cout << "\n-------------------------------------------------------------------------------";
cout << "\nPlease check if you will be able to complete the topics in the given time: "<<endl;
for (int i = 0; i < n; i++)
{
cout <<"For " <<t[i].name << ": " << t[i].time*10 <<" hours" <<"\n";
}
cout<<"\n--------------------------------------";
cout<<"\nIf you are okay press 1 else press 0"<<endl;
cout<<"Enter your choice: ";
cin >> checksub;
if (checksub == 0)
{
cout <<"\n----------------------------------"<<endl;
cout << "You can enter the time manually: ";
for (int i = 0; i < n; i++)
{
cout<<"For Topic "<<i+1<<": ";
cin >> t[i].time;
}
}
for (int i = n; i < 2 * n; i++)
{
t[i].name = t[i - n].name;
t[i].priority = t[i - n].priority / 2;
t[i].weightage = 0;
t[i].difficulty = t[i - n].difficulty / 2;
t[i].time = t[i - n].time / 2.0;
t[i].count = 1;
}
// (value,weight)----(priority,time)
// capacity-tt
//revision of each subject has a priority and time half of the subject
double prepared = fractionalKnapsack(available_time, t, 2 * n);
// cout << prepared; *No NEED*
// return 0; *This Statement Stops the calling the feedback function*
}
else if (option == 2)
{
int n;
cout<< "----------------------------------";
cout << "\nEnter Total Number of subjects: ";
cin >> n;
//cout<< "----------------------------------";
cout<<"\n"<<endl;
subject s[n];
int tcred = 0;
cout<< "----------------------------------------------------------"<<endl;
cout << "Please Enter the Name and Credit points for each subject: \n"<<endl; ;
for (int i = 0; i < n; i++)
{
cout<<"\nEnter the NAME for subject number- "<<i+1<<": ";
cin >> s[i].sname ;
cout<<"\nEnter the CREDIT POINTS for subject number- "<<i+1<<": ";
cin >> s[i].credits;
tcred += s[i].credits;
}
cout<<" \n"<<endl;
//int date;
//cout << "Enter today's date(Format: dd): ";
//cin >> date;
int tgive;
cout<< "--------------------------------------------------------------";
cout << "\nHow much time can you give each day to studies(in hours): ";
cin >> tgive;
cout<< "--------------------------------------------------------------";
cout << "\nEnter number of days you can give for the following exams\n"<<endl;
for (int i = 0; i < n; i++)
{
cout << s[i].sname << ":";
cin >> s[i].examdate;
s[i].time_left = s[i].examdate;
s[i].ttime = s[i].time_left * tgive;
cout<<endl;
}
// int ttime = s[0].time_left * tgive;
cout<< "----------------------------------------------------";
cout << "\nWhat is your preparation level rate it from 1-10? \n10 being highest and 1 being the lowest: \n"<<endl;
for(int i=0;i<n;i++)
{
cout << "For "<< s[i].sname << ": ";
cin >> s[i].prep;
s[i].prepp=100*s[i].prep/10;
// cout<<"Prep Percentage: "<<s[i].prepp<<endl;
}
cout<<endl;
cout<< "---------------------------------------------------------------";
cout << "\nHow much time did you took for doing that preparation(in hours)"<<endl;
for(int i=0;i<n;i++)
{
cout << "For "<< s[i].sname << ": ";
cin>> s[i].pptime;
}
int timp = 0;
for (int i = 0; i < n; i++)
{
s[i].lrate=s[i].pptime/s[i].prepp ;
//cout<<"Learning Rate= "<<s[i].lrate<<endl;
s[i].imp = s[i].credits / ((s[i].prep) * (s[i].time_left));
s[i].profit = s[i].credits / s[i].prep;
timp += s[i].imp;
s[i].rtime = (100-s[i].prepp)*s[i].lrate;;
s[i].stime = s[i].credits * s[i].ttime/ s[i].prep;
s[i].rtime = s[i].rtime + (s[i].stime/2);
s[i].atime=s[i].ttime;
cout<<endl;
// cout<<"Subject Name: "<<s[i].sname<<"Subject Credit: "<<s[i].credits<<" "<<s[i].profit<<"Required Time "<<s[i].stime<<" "<<s[i].prep<<" "<<s[i].time_left<<endl;
}
//cout << "Complete the subjects in the following sequence to maximize your percentage: \n ";
cout<<"\n\t--------------------------- Displaying Schedule Details ---------------------------\n"<<" ";
cout<<"\n\t___________________________________________________________________________________"<<endl;
cout<<setw(20)<<"Subject Name"<<setw(20)<<"Subject Credit"<<setw(25)<<"Required Time(hrs)"<<setw(25)<<"Available Time(hrs)";
cout<<"\n\t-----------------------------------------------------------------------------------";
for(int i=0;i<n;i++)
{
cout<<"\n\t___________________________________________________________________________________";
cout<<"\n"<<setw(20)<<s[i].sname<<setw(15)<<s[i].credits<<setw(22)<<round(s[i].rtime)<<setw(22)<<round(s[i].atime);
cout<<"\n\t___________________________________________________________________________________";
}
cout<<"\n\n";
cout<<"------------------------------------------------------------------";
cout<<"\nAccording to our algorithm the priority should be as follows"<<endl;
printJobScheduling(s, n);
}
//mixed scheduling of all subjects
else if (option == 3)
{
int ask;
//do all difficult chapters together
int n;
cout << "\n---------------------------"<<endl;
cout << "Enter total no. subjects: ";
cin >> n;
subject s[n];
int ttopic = 0;
cout << "\n-------------------------------------------------------------------------------"<<endl;
cout << "Enter name of each Subject, their Credits & Number of Topics in each Subject: ";
for (int i = 0; i < n; i++)
{
cout<<"\n---------------";
cout<<"\nNumber: "<<i+1<<endl;
cout<<"Subject Name: ";
cin >> s[i].sname;
cout<<"Subject Credit: ";
cin>> s[i].credits;
cout<<"Number of Topics in it: ";
cin>> s[i].topics;
cout<<endl;
ttopic += s[i].topics;
}
cout << "\n";
sort(s, s + n, cmpsub);
//cout<<"sorted on basis of course credits";
//cout<<"ttopic is"<<ttopic;
/*
for(int i=0;i<n;i++)
{
cout<<s[i].sname<<"\n";
cout<<s[i].topics<<"\n";}*/
topic it[ttopic * n];
int y = 0;
cout << "\n-----------------------------------------------------------------------------------------------"<<endl;
for (int i = 0; i < n; i++)
{
cout << "Enter the name of each Topic with its importance in exam and Difficulty level according to you."<<endl;
cout << "From 1-10_____1 being the easiest for the subject"<<endl;
cout <<"For "<< s[i].sname << ": "<<endl;
for (int j = 0; j < s[i].topics; j++)
{
cout<<"\n-------------------"<<endl;
cout<<"Topic Number: "<<j+1<<endl;
cout<<"Topic Name: ";
cin >> it[y].name;
cout<<"Topic Weightage: ";
cin >> it[y].weightage;
cout<<"Topic difficulty: ";
cin >> it[y].difficulty;
cout<<endl;
it[y].imp = it[y].weightage * s[i].credits * it[y].difficulty;
y++;
}
}
cout << "\n----------------------------------------------------------------------------------------"<<endl;
cout << "Do you want to do major chapters first ( press 1 ) or the most difficult ones (press 0)? ";
cin >> ask;
if (ask == 0)
{
//sort on the basis of difficulty
sort(it, it + (n * ttopic), cmpDiff);
cout << "\n----------------------------------------------------"<<endl;
cout << "Sorted by difficulty in each topic faced by you:\n";
for (int i = (n * ttopic) - 1; i >= 0; i--)
{
cout << it[i].name << "\n";
}
}
else if (ask == 1)
{
//sort on the basis of importance
sort(it, it + (n * ttopic), cmpImp);
cout << "\n----------------------------------------------------"<<endl;
cout << "Sorted by importance of each subject in exam: ";
for (int i = (n * ttopic) - 1; i >= 0; i--)
{
cout << it[i].name << "\n";
}
}
}
else
{
cout<<"\n-----------------------------------------"<<endl;
cout<<"The Option Number you chose is not their"<<endl;
cout<<"\n-------------------------------------"<<endl;
cout<<"Thank You! :)"<<endl;
return 0;
}
user_feedback();
return 0;
}
=======
#include <bits/stdc++.h>
using namespace std;
class topic
{
public:
string name;
int count=0;
int priority;
int difficulty;
double time;
int weightage;
int imp;
};
class subject
{
public:
string sname;
topic c[20];
int credits;
int prep;
float stime;
int imp;
float profit;
int examdate;
int exam_month;
int time_left;
int topics;
int diff;
int s[100];
};
void printJobScheduling(subject arr[], int n);
double fractionalKnapsack(int W, topic arr[], int n);
bool cmp(topic a, topic b)
{
double r1 = (double)a.priority / a.time;
double r2 = (double)b.priority / b.time;
return r1 > r2;
}
bool cmpsub(subject a,subject b)
{
return (a.credits<b.credits);
}
bool cmpDate(subject s1,subject s2)
{
return s1.time_left<s2.time_left;
}
bool cmpDiff(topic a,topic b)
{
return (a.difficulty<b.difficulty);
}
bool cmpImp(topic a,topic b)
{
return (a.imp<b.imp);
}
bool comparison(subject a, subject b)
{
return (a.imp > b.imp);
}
void printJobScheduling(subject arr[], int n)
{
sort(arr, arr+n, comparison);
for (int i=0;i<n;i++) {
cout<<"\n"<<i+1<<") "<<arr[i].sname; // updated the function and it works correctly now( error RTE before user feedback() )
}
cout<<"\n";
int result[n];
bool slot[n];
for (int i=0; i<n; i++)
slot[i] = false;
for (int i=0; i<n; i++)
{
for (int j=min(n, arr[i].time_left)-1; j>=0; j--)
{
if (slot[j]==false)
{
result[j] = i; // Add this job to result
slot[j] = true; // Make this slot occupied
break;
}
}
}
for (int i=n-1; i>=0; i--)
{
if (slot[i])
{
cout << arr[result[i]].sname << "\n";
}
}
}
double fractionalKnapsack(float W, topic arr[], int n)
{
sort(arr, arr + n, cmp);
int curMarks = 0; // Current weight in knapsack
double finalvalue = 0.0; // Result (value in Knapsack)
for (int i = 0; i < n; i++)
{
if (curMarks + arr[i].time <= W)
{
curMarks += arr[i].time;
finalvalue += arr[i].weightage;
if(arr[i].count==0)
{
cout<<arr[i].name<<" ";
}
cout<<"\n";
if(arr[i].count==1)
{
float trev=arr[i].time/2;
float tpaper=arr[i].time/4;
float tdoubts=arr[i].time/4;
cout<<"You can revise the topic " <<arr[i].name<< " in "<<trev<<" hours"<<"\n";
cout<<"Do not forget to take a look at last year questions for this topic in the next "<<tpaper<<" hours"<<"\n";
cout<<"Try to clear your doubts about this topic in next "<<tdoubts<<" hours"<<"\n";cout<<"\n";
cout<<"--------------------------------------------------------\n";
}
}
else
{
int remain = W - curMarks;
finalvalue += arr[i].weightage * ((double) remain / arr[i].time);
cout<<"You can only do some part of the chapter ";
break;
}
if(curMarks>=W){return 0.0;}
}
return finalvalue;
}
void user_feedback(){
int ratings;
cout<<"Please give us a feedback on the basis of the preparation schedule provided to you:\nRate us out of 5 where 1 symbolises lowest\n";
cin>>ratings;
cout<<"Thank you,:)";
}
/*
end
COMPLETE FOR 1 SUBJECT
*/
int main()
{
int option;
cout << "------------MENU------------\n";
cout << "\nEnter the number as follows:\n";
cout << "0 to schedule studies for all subjects for a long period of time\n1 to schedule a given subject in limited time\n2 for mixed schedule of all subjects(if you have enough time)";
cout << "\n---- ";
cin >> option;
if (option == 1)
{
int n;
cout << "Enter the no. of topics: ";
cin >> n;
cout<<"--------------------------------------------------------\n";
int total_diff = 0; // sp
topic t[2 * n];
cout << "Enter name of each topic: \n";
for (int i = 0; i < n; i++)
{
cout<<i+1<<") ";
cin >> t[i].name;
}
cout << "--------------------------------------------------------\nEnter priority of each topic i.e. expected weightage: \n";
for (int i = 0; i < n; i++)
{
cout << t[i].name << " : ";
cin >> t[i].priority;
t[i].weightage = t[i].priority;
t[i].count = 0;
}
cout << "--------------------------------------------------------\n";
cout<<"Enter difficulty level of each topic based on your own understanding from(1-10) 1 being the easiest: \n";
for (int i = 0; i < n; i++)
{
cout << t[i].name << " : ";
cin >> t[i].difficulty;
total_diff = total_diff + t[i].difficulty;
}
total_diff = total_diff + total_diff / 2;
float total_time; // tt
float focused_time; // eff
cout << "--------------------------------------------------------\nEnter total time available to study this subject in hours: ";
cin >> total_time;
cout << "--------------------------------------------------------\nHow much you can resist yourself from using phone during exams?(1-10): ";
cin >> focused_time;
cout<<"\n--------------------------------------------------------\n";
float available_time = total_time * focused_time / 10; //at
cout << "Allotted time: " << available_time << "\n";
cout << "Difficulty Level: " << total_diff << "\n";
float utilised_val = available_time / total_diff; //ut
cout << "Utilization Time: " << utilised_val << "\n";
cout<<"--------------------------------------------------------\n";
for (int i = 0; i < n; i++)
{
t[i].time = utilised_val * t[i].difficulty / 10;
cout << t[i].name << " ---> " << t[i].time * 10 << "\n";
}
cout<<"--------------------------------------------------------\n";
int checksub;
cout << "The time is: \n";
for (int i = 0; i < n; i++)
{
cout << t[i].name << " ---> " << t[i].time << "\n";
}
cout<<"\n--------------------------------------------------------\n";
cout << "Please check if you will be able to complete the topics in the given time \nIf okay press 1 else press 0: ";
cin >> checksub;
cout<<"\n--------------------------------------------------------\n";
if (checksub == 0)
{
cout << "You can enter the time manually: \n";
for (int i = 0; i < n; i++)
{
cin >> t[i].time;
}
}
for (int i = n; i < 2 * n; i++)
{
t[i].name = t[i - n].name;
t[i].priority = t[i - n].priority / 2;
t[i].weightage = 0;
t[i].difficulty = t[i - n].difficulty / 2;
t[i].time = t[i - n].time / 2.0;
t[i].count = 1;
}
// (value,weight)----(priority,time)
// capacity-tt
//revision of each subject has a priority and time half of the subject
double prepared = fractionalKnapsack(available_time, t, 2 * n);
cout << prepared<<"\n--------------------------------------------------------\n";
//return 0;
}
else if (option == 0)
{
int n;
cout << "Enter total no. subjects: ";
cin >> n;
subject s[n];
int tcred = 0;
cout << "Enter name and credits for each subject: \nPrint the name and the credits separating with a space \n";
cout<<"--------------------------------------------------------\n";
for (int i = 0; i < n; i++)
{
cout<< i+1<<") ";
cin >> s[i].sname >> s[i].credits;
tcred += s[i].credits;
}
int date;
cout << "--------------------------------------------------------\nEnter today's date (Format: dd): ";
cin >> date;
int month;
cout<<"Enter the month (Format: mm): ";
cin>>month;
int tgive;
cout << "--------------------------------------------------------\nHow much time can you give each day to studies(in hours): ";
cin >> tgive;
cout << "--------------------------------------------------------\nEnter the date and month for the following exams: \n\n";
for (int i = 0; i < n; i++)
{
//cout << s[i].sname << ":\nenter date: \n";
cout<< "Date of the exam for subject "<<s[i].sname<<": ";
cin >> s[i].examdate;
// cout << "\nenter month: ";
cout<< "Month of the exam for subject "<<s[i].sname<<": ";
cin>>s[i].exam_month;
if(s[i].exam_month==month){//calculating the time left if the exam is on the same month as the date
s[i].time_left=s[i].examdate-date+1;
//cout<<"time left:"<<" "<<s[i].time_left<<" days"<<endl;
}
else if(s[i].exam_month>month){//calculating the time left if the exam is scheduled in later months
if(s[i].examdate>date){
int month_value=s[i].exam_month-month;
s[i].time_left = month_value*(30+abs(s[i].examdate - date + 1));
}
else{
s[i].time_left=30-date+s[i].examdate+1;
//cout<<"time left: "<<s[i].time_left<<" days"<<endl;
}
}
}
cout<<"--------------------------------------------------------\n";
for (int i=0 ; i<n ; i++ )
{
cout<<"time left for "<<s[i].sname<<" subject : "<<s[i].time_left<<" days"<<endl;
}
cout<<"--------------------------------------------------------\n";
int ttime = s[0].time_left * tgive;
cout << "How much previous preparation do you have on a scale of 1 to 10? \n10 being highest and 1 being the lowest: \n";
int timp = 0;
for (int i = 0; i < n; i++)
{
cout << s[i].sname << ": ";
cin >> s[i].prep;
s[i].imp = s[i].credits*ttime / ((s[i].prep) * (s[i].time_left)); // calculating importance of each subject
s[i].profit = s[i].credits / s[i].prep;
timp += s[i].imp;
s[i].stime = s[i].credits * ttime / s[i].prep;
//cout<<s[i].sname<<" "<<s[i].credits<<" "<<s[i].profit<<" "<<s[i].stime<<" "<<s[i].prep<<" "<<s[i].time_left<<endl;
}
cout << "Complete the subjects in the following sequence to maximize your percentage:\n--------------------------------------------------------\n";
printJobScheduling(s, n);
cout<<"--------------------------------------------------------\n";
}
//mixed scheduling of all subjects