-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.c
1279 lines (1216 loc) · 46.9 KB
/
admin.c
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 "common.h"
#include "admin.h"
#include "login.h"
#include "analytics.h"
/*int main(){
welcomepage_admin();
return 0;
}*/
void preview_all_questions(int quiz_id){ //displays all questions without edit option
clearscr();
printf("Quiz name : %s\n",quizlist.quiz[quiz_id].name);
for (int i = 0; i < quizlist.quiz[quiz_id].no_of_questions; i++){
for (int alt = 0; alt < max_alternative_q; alt++){
if(question[quiz_id][i][alt].status != 'E') {
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%d.%d~~~~~~~~~~~~~~~~~~~~~~~~\n\n",i+1,alt+1);
printf("Marks - %d\n\n",question[quiz_id][i][alt].marks);
printf("Statement:\n%s\n",question[quiz_id][i][alt].statement);
printf("Solution:\n%s\n",question[quiz_id][i][alt].solution);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
}
}
printf("press any button to proceed\n");
wait_for_enter();
admin_quizdetails(quiz_id);
}
void change_max_attempts(int quiz_id){
clearscr();
printf("Quiz : %s\n",quizlist.quiz[quiz_id].name);
printf("Type new max_attempts\n");
int response;
response = scanf_int(max_alternative_q,1);
if (response < quizlist.quiz[quiz_id].no_of_max_attempts){
for (int i = 0; i < max_users; i++){
if(response < quizes_attempted[i][quiz_id].no_attempts){
printf("Cann't change becouse few users already attempted more than this number\nType enter to go back");
wait_for_enter();
admin_quizdetails(quiz_id);
return;
}
}
printf("Are you sure to change the maximum attempts from %d to %d?\n",quizlist.quiz[quiz_id].no_of_max_attempts,response);
char res;
do{
scanf("%c",&res);
clearBuf();
if(res == 'y' || res == 'Y'){
quizlist.quiz[quiz_id].no_of_max_attempts = response;
appdata_save(0);
printf("maximum attempts changed successfully, Type enter to continue\n");
wait_for_enter();
admin_quizdetails(quiz_id);
return;
}
else if(res == 'n' || res == 'N'){
admin_quizdetails(quiz_id);
return;
}
else printf("%sInvalid response try again%s\n", red, normal);
}while(1);
}
else{
printf("you are going to increase the number of max attempts for the quiz to make this change you may need to add few more questions\nmake sure that there are sufficient alternate questions by editing question option\n");
printf("continue?(y/n)\n");
char res1;
do{
scanf("%c",&res1);
clearBuf();
if(res1 == 'y' || res1 == 'Y'){
for (int ques = 0; ques < quizlist.quiz[quiz_id].no_of_questions; ques++){
int alts= 0 ;
for (int alt = 0; alt < max_alternative_q; alt++){
if (question[quiz_id][ques][alt].statement[0] != '\0') alts++;
}
if(alts < response) {
printf("few alternate questions found at %d question, please go back and add enough alternate questions\nType any key to go back'\n",ques+1);
wait_for_enter();
admin_quizdetails(quiz_id);
return;
}
}
printf("Are you sure to change the maximum attempts from %d to %d?\n",quizlist.quiz[quiz_id].no_of_max_attempts,response);
char res;
do{
scanf("%c",&res);
clearBuf();
if(res == 'y' || res == 'Y'){
quizlist.quiz[quiz_id].no_of_max_attempts = response;
appdata_save(0);
printf("maximum attempts changed successfully, press any key to continue\n");
wait_for_enter();
admin_quizdetails(quiz_id);
return;
}
else if(res == 'n' || res == 'N'){
admin_quizdetails(quiz_id);
return;
}
else printf("%sInvalid response try again%s\n", red, normal);
}while(1);
}
else if (res1 == 'n'||res1=='N'){
admin_quizdetails(quiz_id);
return;
}
else printf("%snot a valid response try again%s\n", red, normal);
}while(1);
}
}
void preview_question(int quiz_id,int ques_id){
int alts= 0;
for (int alt = 0; alt < max_alternative_q; alt++){
if(question[quiz_id][ques_id][alt].status != 'E') {
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%d.%d~~~~~~~~~~~~~~~~~~~~~~~~\n\n",ques_id+1,alt+1);
printf("Marks - %d\n\n",question[quiz_id][ques_id][alt].marks);
printf("Statement:\n%s\n",question[quiz_id][ques_id][alt].statement);
printf("Solution:\n%s\n",question[quiz_id][ques_id][alt].solution);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
alts++;
}
}
printf("\n Type corresponding alt number to edit\notherwise type 0 to add alt questions/solution(you have to rewrite the total question and solution)\n Type -1 to go back to questions page\n");
int res;
res = scanf_int(alts,-1);
if(res==0){
if(alts != max_alternative_q){
add_question(quiz_id,ques_id,alts);
appdata_save(1);
}
else if (alts == max_alternative_q){
printf("Can't add alt anymore all %d alts exists", max_alternative_q);
}
preview_question(quiz_id,ques_id);
}
else if(res > 0 && res <= alts){
add_question(quiz_id,ques_id,res-1);
appdata_save(1);
preview_question(quiz_id,ques_id);
}
else if (res == -1) {
edit_questions(quiz_id);
}
}
void preview_quiz(int quiz_Id){
clearscr();
printf("Quiz-%s\n\n",quizlist.quiz[quiz_Id].name);
printf("~~~QUESTION_NO~~~~~~~~~~~~~~~NO.OF_ALTS~~~~~~~~~~~~~~~Marks\n");
for (int qid = 0; qid <quizlist.quiz[quiz_Id].no_of_questions; qid++){
int no_of_alts= 0;
for (int i = 0; i < max_alternative_q; i++){
if(question[quiz_Id][qid][i].status != 'E') no_of_alts++;
}
printf(" %d %d %d\n",qid+1,no_of_alts,question[quiz_Id][qid][0].marks);
}
}
void add_question(int quiz_id,int question_id,int alt_id){
clearscr();
int resp;
if (question[quiz_id][question_id][0].marks == 0) {
printf("Marks of %d question?\n",question_id+1);
resp = scanf_int(1000,1);
question[quiz_id][question_id][0].marks = resp;
}
for (int ip = 0; ip < max_alternative_q; ip++){
question[quiz_id][question_id][ip].marks=question[quiz_id][question_id][0].marks;
}
char check='n';
while(check != 'y'){
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%d.%d~~~~~~~~~~~~~~~~~~~~~~~~\n\n",question_id+1,alt_id+1);
printf("type statment of %d-alternate for %d question(%d marks)\n\t(press ENTER 3 times to submit question)\n",alt_id+1,question_id+1,question[quiz_id][question_id][0].marks);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
multiline_input(question[quiz_id][question_id][alt_id].statement,max_question_length);
printf("\nType Solution:\n");
smart_fgets(question[quiz_id][question_id][alt_id].solution,max_answer_length,stdin);
printf("\npreview:\n\n%s\n\n",question[quiz_id][question_id][alt_id].statement);
printf("Solution:\n");
printf("%s\n\n",question[quiz_id][question_id][alt_id].solution);
printf("continue(y/n)? or rewrite this question?\n");
char res;
do {
scanf("%c",&res);
clearBuf();
if(res=='y'||res=='Y'){
check = 'y';
}
else if(res == 'n' || res == 'N') continue;
else printf("%sNot a valid response try again%s\n", red, normal);
}while(res != 'y'&& res != 'Y' && res!= 'n'&&res!='N');
}
for(int user = 0; user<max_users;user++) response[user][quiz_id][question_id][alt_id].status = 'N'; //changing status from E to N if question is filled.
question[quiz_id][question_id][alt_id].status = 'N';
}
void edit_questions(int quiz_id){
preview_quiz(quiz_id);
printf("Type ques_number to preview,edit or add alternate question numbers\nType 0 to create questions\nType -1 to exit\n");
int res;
res = scanf_int(quizlist.quiz[quiz_id].no_of_questions,-1);
if(res== -1){
admin_quizdetails(quiz_id);
}
else if(res >0 && res <= quizlist.quiz[quiz_id].no_of_questions){
preview_question(quiz_id,res-1);
}
else if(res == 0){ //adding questions.
printf("Type no.of question to added extra(you can add %d maximum)\n",max_q_per_quiz-quizlist.quiz[quiz_id].no_of_questions);
int res2=0;
res2 = scanf_int(max_q_per_quiz-quizlist.quiz[quiz_id].no_of_questions,0);
if(res2 == 0){
edit_questions(quiz_id);
return;
}
else if(res2 > 0){
if (res2 <= max_q_per_quiz-quizlist.quiz[quiz_id].no_of_questions){
quizlist.quiz[quiz_id].no_of_questions += res2;
ques_initialize(quizlist.quiz[quiz_id].no_of_questions-res2,quiz_id);
addquestions_initial(quizlist.quiz[quiz_id].no_of_questions-res2,quiz_id);
return;
}
}
}
}
void ques_initialize(int questart_id,int quiz_id){
if(questart_id == 0){
for(int tid=0;tid<max_tags;tid++) quizlist.quiz[quiz_id].tag_ids[tid] = 0;
}
for (int i = questart_id; i <= quizlist.quiz[quiz_id].no_of_questions; i++){
for(int d=0;d <max_alternative_q;d++){
question[quiz_id][i][d].statement[0] = '\0';
question[quiz_id][i][d].solution[0] = '\0';
question[quiz_id][i][d].marks = 0;
for(int uid = 0;uid < max_users;uid++){
response[uid][quiz_id][i][d].status = 'E';
response[uid][quiz_id][i][d].answer[0] = '\0';
quizes_attempted[uid][quiz_id].attempt[d].result.attempted = 0;
quizes_attempted[uid][quiz_id].attempt[d].result.correct = 0;
quizes_attempted[uid][quiz_id].attempt[d].result.incorrect=0;
quizes_attempted[uid][quiz_id].attempt[d].result.score= 0;
}
question[quiz_id][i][d].status = 'E';
}
}
}
void addquestions_initial(int questart_id,int quiz_id){
preview_quiz(quiz_id);
printf("press ENTER to start entering questions\n");
wait_for_enter();
for (int i = questart_id; i < quizlist.quiz[quiz_id].no_of_questions; i++){
clearscr();
printf("%s\n",quizlist.quiz[quiz_id].name);
for (int alt = 0; alt <quizlist.quiz[quiz_id].no_of_max_attempts ; alt++){
add_question(quiz_id,i,alt);
}
int diff = max_alternative_q - quizlist.quiz[quiz_id].no_of_max_attempts;
char res2 = 'y';
while(diff > 0 && res2 != 'n'){
printf("You can still add(optional) %d no.of alternate questions would like to continue?(y/n)",diff);
do {
scanf("%c",&res2);
clearBuf();
if(res2 == 'y' || res2 == 'Y'){
add_question(quiz_id,i,max_alternative_q-diff);
diff--;
}
else if ( res2 == 'n'||res2 =='N'){
diff = 0;
res2 = 'n';
}
else printf("%snot a valid input%s\n", red, normal);
}while(res2 != 'y'&& res2 != 'Y' && res2!= 'n'&&res2!='N');
}
}
appdata_save(1);
edit_questions(quiz_id);
}
void add_instrucion_page(int quiz_id){
clearscr();
printf("\nType the instructions :(press enter one time to start a new line and press enter three times to end adding instruction.)\n");
printf("\n*****************************************************************************************************************************\n");
multiline_input(quizlist.quiz[quiz_id].instructions,1000);
clearscr();
printf("Preveiw :\n");
printf("\n********************************************************************************************************\n");
printf("%s",quizlist.quiz[quiz_id].instructions);
printf("\n***********************************************************************************************************\n");
printf("would like to continue?(y/n)");
char res = takeyorno();
if(res == 'n'){
add_instrucion_page(quiz_id);
}
appdata_save(0);
clearscr();
}
void addquiz(){
quizlist.no_of_quizes = quizlist.no_of_quizes+1;//increasing no.of quizes.
int i = quizlist.no_of_quizes - 1;//i is index for quiz array.
printf("Quiz name?\n");//taking quiz name.
char x[101];
smart_fgets(x,101,stdin);
strcpy(quizlist.quiz[i].name,x);
quizlist.quiz[i].no_of_students_attempted=0;//initialising to zero.
//no.of questions.
printf("no.of questions?(type number between 1 to %d)\n", max_q_per_quiz);
int res;
scanf("%d",&res);
clearBuf();
while(res <= 0 || res >= max_q_per_quiz){
printf("%sinvalid response type again(should be a number in range 1 to %d)%s\n", red, max_q_per_quiz, normal);
scanf("%d",&res);
clearBuf();
}
quizlist.quiz[i].no_of_questions = res;
//no_of_max_attempts part.
printf("no.of maximum attepts?(type number between 1 to %d)\n", max_alternative_q);
scanf("%d",&res);
clearBuf();
while(res <= 0 || res >= 6){
printf("%sinvalid response type again(should be a number in range 1 to %d)%s\n", red, max_alternative_q, normal);
scanf("%d",&res);
clearBuf();
}
quizlist.quiz[i].no_of_max_attempts = res;
printf("duration of quiz?(type number in minutes)\n");
int response = scanf_int(10000,1);
quizlist.quiz[i].max_time = response * 60 ; // in seconds.
//conformation.
printf("you have to add atleast %d questions\nWould you like to continue?(y/n)\n",quizlist.quiz[i].no_of_max_attempts*quizlist.quiz[i].no_of_questions);
char res2;
do {
scanf("%c",&res2);
clearBuf();
if(res2=='y'||res2=='Y'){
quizlist.quiz[quizlist.no_of_quizes-1].instructions[0] = '\0'; //initializing quiz instructions.
quizlist.quiz[quizlist.no_of_quizes -1].visible = 0; //making quiz not visible by default.
add_instrucion_page(quizlist.no_of_quizes-1);
ques_initialize(0,quizlist.no_of_quizes-1);
addquestions_initial(0,i);
}
else if(res2=='n'||res2=='N'){
quizlist.no_of_quizes = quizlist.no_of_quizes-1;
showqlist_admin();
}
else printf("%sNot a valid response try agian%s\n", red, normal);
}while(res2 != 'n' && res2 != 'y' && res2!= 'N' && res2!='Y');
}
void admin_Matrix(int stu_id,int index, int attempt) {
clearscr();
printf("-------------------------------------------\n %s \n", quizlist.quiz[index].name);
printf("-------------------------------------------\n %s's Analysis Matrix \n\n",userlist[stu_id].username);
quiz_result_admin(stu_id,index, attempt);
char color[8];
for (int i = 0; i < quizlist.quiz[index].no_of_questions; ++i) {
char status=response[stu_id][index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i][1]].status;
if (status=='U') {
strcpy(color,yellow);
}
else if (status=='S') {
strcpy(color,cyan);
}
else if (status=='C') {
strcpy(color,green);
}
else if (status=='W') {
strcpy(color,red);
}
if (i%5==0) {
printf("\n");
}
if (i+1<10) {
printf(" %d) %s[%c]%s (%d/%d) ", i+1, color, status, normal, quizes_attempted[stu_id][index].attempt[attempt].marks[i] ,question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i][1]].marks);
}
else {
printf("%d) %s[%c]%s (%d/%d) ", i+1, color, status, normal, quizes_attempted[stu_id][index].attempt[attempt].marks[i], question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i][1]].marks);
}
}
printf("\n\nKey:\n%s[U]%s Unattempted (p/q) p Marks Obtained Out of q\n", yellow, normal);
printf("%s[S]%s Seen\n", cyan, normal);
printf("%s[C]%s Correct\n", green, normal);
printf("%s[W]%s Wrong\n", red, normal);
printf("\n\nEnter question number you wish to analyse or '0' to exit analytics,\n");
int num;
scanf("%d", &num);
clearBuf();
if (num==0) {
clearscr();
response_admin(index);
}
else if (num>0&&num<=quizlist.quiz[index].no_of_questions) {
clearscr();
see_response_admin(stu_id,num, index, attempt);
}
else {
clearscr();
printf("%sInvalid Input!%s\n", red, normal);
admin_Matrix(stu_id,index, attempt);
}
}
void quiz_result_admin(int stu_id,int index, int attempt) {
printf("The details are: \n");
printf("%s's score is %d \n",userlist[stu_id].username,quizes_attempted[stu_id][index].attempt[attempt].result.score);
printf("No. of correct answers are %d \n",quizes_attempted[stu_id][index].attempt[attempt].result.correct);
printf("No. of incorrect answers are %d \n\n",quizes_attempted[stu_id][index].attempt[attempt].result.incorrect);
if (quizes_attempted[stu_id][index].attempt[attempt].time_taken%60<9) {
printf("Time taken : %d:0%d \n",quizes_attempted[stu_id][index].attempt[attempt].time_taken/60,quizes_attempted[stu_id][index].attempt[attempt].time_taken%60);
}
else {
printf("Time taken : %d:%d \n",quizes_attempted[stu_id][index].attempt[attempt].time_taken/60,quizes_attempted[stu_id][index].attempt[attempt].time_taken%60);
}
}
void see_response_admin(int stu_id,int i, int index, int attempt) {
clearscr();
printf("-------------------------------------------\n %s-%s \n", quizlist.quiz[index].name,userlist[stu_id].username);
printf("-------------------------------------------\n Question %d (%d Marks)\n\n", i, question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].marks);
printf("\nQuestion:\n%s\n\n", question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].statement);
printf("Solution:\n%s\n\n",question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].solution);
printf("Response:\n%s\n\n", response[stu_id][index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].answer);
printf("Score: %d/%d\n\n", quizes_attempted[stu_id][index].attempt[attempt].marks[i-1], question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].marks);
printf("Enter 'e' to exit ,'m' to grade question manually or 'n' to proceed to next question\n");
char com;
E:
com=getchar();
clearBuf();
if (com=='e') {
clearscr();
admin_Matrix(stu_id,index, attempt);
}
else if (com=='n') {
clearscr();
if (i <quizlist.quiz[index].no_of_questions) { //next question index is less than equal last question index
see_response_admin(stu_id, ++i , index, attempt);
}
else { //If not go to first question
see_response_admin(stu_id, 1, index, attempt);
}
}
else if(com =='m'){
printf("Enter new marks\n");
int res = scanf_int(question[index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].marks,0);
if(res != 0 && quizes_attempted[stu_id][index].attempt[attempt].marks[i-1] == 0){
quizes_attempted[stu_id][index].attempt[attempt].result.correct++;
quizes_attempted[stu_id][index].attempt[attempt].result.incorrect--;
response[stu_id][index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].status = 'C';
}
if(res == 0 && quizes_attempted[stu_id][index].attempt[attempt].marks[i-1] != 0){
quizes_attempted[stu_id][index].attempt[attempt].result.correct--;
quizes_attempted[stu_id][index].attempt[attempt].result.incorrect++;
response[stu_id][index][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][0]][quizes_attempted[stu_id][index].attempt[attempt].q_bank[i-1][1]].status = 'W';
}
quizes_attempted[stu_id][index].attempt[attempt].marks[i-1] = res;
appdata_save(1);
printf("score changed successfully\nType any character to proceed\n");
wait_for_enter();
clearscr();
see_response_admin(stu_id, i,index,attempt);
return;
}
else {
printf("%sInvalid option! Please try again,%s\n", red, normal);
goto E;
}
}
void response_admin(int quiz_id){
clearscr();
printf("Quiz name: %s\n",quizlist.quiz[quiz_id].name);
if (quizlist.quiz[quiz_id].no_of_students_attempted != 0){
int ids[no_of_currentusers];
int max =0;
printf("S.no~~~~~~~~~~~~User name~~~~~~~~~~attempts\n");
for (int i = 0; i < no_of_currentusers; i++){
if(quizes_attempted[i][quiz_id].no_attempts != 0){
ids[max] = i;
printf("%d %s %d\n",++max,userlist[i].username,quizes_attempted[i][quiz_id].no_attempts);
}
}
printf("Type corresponding serial number to veiw responses\nType 0 to go back\n");
int res;
res = scanf_int(max,0);
if(res ==0){
admin_quizdetails(quiz_id);
return;
}
else{
if(quizes_attempted[ids[res-1]][quiz_id].no_attempts == 1){
clearscr();
admin_Matrix(ids[res-1],quiz_id,0);
clearscr();
return;
}
else{
printf("User has attempted this quiz %d times\nType an attempt number to veiw responses(greater number implies recent attempt)\n",quizes_attempted[ids[res-1]][quiz_id].no_attempts);
int resp = scanf_int(quizes_attempted[ids[res-1]][quiz_id].no_attempts,1);
clearscr();
admin_Matrix(ids[res-1],quiz_id,resp-1);
return;
}
}
}
else {
printf("no one attempted the quiz\nPress ENTER to goback");
wait_for_enter();
admin_quizdetails(quiz_id);
}
}
void change_marks(int quiz_id){
printf("Type the question number to change marks of that question\nType 0 to goback\n");
int res;
int check = 0;
do {
scanf("%d",&res);
clearBuf();
if(res == 0 ){
admin_quizdetails(quiz_id);
check =1;
}
else if(res <= quizlist.quiz[quiz_id].no_of_questions && res >0){
printf("type new marks for question %d(previously %d marks)\n",res,question[quiz_id][res-1][0].marks);
int res2;
check = 1;
int check2 = 0;
do {
scanf("%d",&res2);
clearBuf();
if(res2 >0 ){
for(int i = 0;i <max_alternative_q;i++) question[quiz_id][res-1][i].marks = res2;
appdata_save(0);
check2 = 1;
admin_quizdetails(quiz_id);
}
else printf("%sNot a valid response try again%s\n", red, normal);
}while(check2 == 0);
}
else printf("%sNot a valid response try again%s\n", red, normal);
}while(check == 0);
}
void delete_quiz(int quiz_id){
printf("Are you sure to delete this quiz?(y/n)\n");
do{
char res;
scanf("%c",&res);
if(res == 'y' || res == 'Y'){
for(int id= quiz_id ; id < quizlist.no_of_quizes;id++){ //changes to struct quiz.
quizlist.quiz[id] = quizlist.quiz[id+1];
}
for(int stu_id = 0; stu_id < no_of_currentusers;stu_id++){ // changes to array quizzes attempted and responses;
for(int id= quiz_id ; id < quizlist.no_of_quizes;id++){
quizes_attempted[stu_id][id] = quizes_attempted[stu_id][id+1];
for(int ques_id = 0;ques_id< max_q_per_quiz;ques_id++){
for(int alt_id= 0;alt_id < max_alternative_q;alt_id++){
response[stu_id][id][ques_id][alt_id] = response[stu_id][id+1][ques_id][alt_id];
}
}
}
}
quizlist.no_of_quizes--;
appdata_save(1);
printf("quiz deleted succesfully\nType any key to go back\n");
wait_for_enter();
showqlist_admin();
return;
}
else if (res == 'n' || res == 'N'){
admin_quizdetails(quiz_id);
return;
}
else{
printf("%sInvalid response please type again!%s", red, normal);
}
}while(1);
}
void tag_quiz(int quiz_id){
printf("Type corresponding tag number from above printed taglist to remove tag\n 0 to add a tag\n");
int response=-1;
do{
response = scanf_int(max_tags,0);
if(response == 0) break;
if(taglist[response-1][0]=='\0'){
printf("%sNot a valid response try again%s\n", red, normal);
response = -1;
}
}while(response==-1);
if(response==0){
clearscr();
printf("Available tags :\n");
int num = 0;
for (int i = 0; i < max_tags; i++){
if(quizlist.quiz[quiz_id].tag_ids[i] == 0) {
if(taglist[i][0]!= '\0'){
printf("%d\t%s\n",i+1,taglist[i]);
num++;
}
}
}
if(num !=0){
printf("\nType the corresponding number to add a tag\n");
int res = scanf_int(max_tags,1);
if(taglist[res-1][0] != '\0'){
quizlist.quiz[quiz_id].tag_ids[res-1] = 1;
appdata_save(0);
printf("Quiz tagged successfully\npress ENTER to continue\n");
wait_for_enter();
admin_quizdetails(quiz_id);
}
else{
printf("Error can't add empty tag try again\npress ENTER to continue\n");
wait_for_enter();
admin_quizdetails(quiz_id);
}
}
else{
printf("No tags left to tag\npress ENTER to continue\n");
wait_for_enter();
admin_quizdetails(quiz_id);
}
}
else{
if(quizlist.quiz[quiz_id].tag_ids[response-1]== 1){
printf("Are you sure to remove %s tag for this quiz?(y/n)\n",taglist[response-1]);
char resp = takeyorno();
if(resp == 'y'){
quizlist.quiz[quiz_id].tag_ids[response-1] = 0;
appdata_save(0);
printf("Tag removed successfully\npress ENTER to conltinue\n");
wait_for_enter();
admin_quizdetails(quiz_id);
}
else{
admin_quizdetails(quiz_id);
}
}
else{
printf("%sInvalid response press ENTER to continue%s\n", red, normal);
wait_for_enter();
admin_quizdetails(quiz_id);
}
}
}
void admin_quizdetails(int n){
clearscr();
printf("Quiz name : %s\n",quizlist.quiz[n].name);
printf("\n*****************************************INSTRUCTIONS*********************************************\n");
printf("%s",quizlist.quiz[n].instructions);
printf("\n****************************************************************************************************\n");
printf("No.of questions %d\n",quizlist.quiz[n].no_of_questions);
printf("No.of maximum attempts : %d\n",quizlist.quiz[n].no_of_max_attempts);
printf("Max time : %d min\n",quizlist.quiz[n].max_time/60);
printf("\nTags :\n");
int tagnum = 0,num =0; //tagnum no tags tagged to this quiz , num is no.of totall tags in system at present.
for(int ti=0; ti < max_tags;ti++){
if(taglist[ti][0] !='\0'){
if(quizlist.quiz[n].tag_ids[ti] == 1 ){
printf("%d)%s\n",ti+1,taglist[ti]);
tagnum++;
}
num ++;
}
}
if(tagnum == 0) printf("(no tags quiz is open for all users)\n");
if(quizlist.quiz[n].visible == 0){
printf("Availability :\n%sNot visible to all users%s\n",red, normal);
}
else if(quizlist.quiz[n].visible == 1){
printf("Availability :\n%sOnly Instructions visible%s\n", yellow,normal);
}
else if(quizlist.quiz[n].visible == 2){
printf("Availability :\n%sAvailable to tagged users%s\n", green, normal);
}
printf("\nType\n r : to view student responses\n m : To change distrubution of marks\n e : To add questions/edit existing questions \n p : to preview whole question paper\n c : to change maximum number of attempts\n d : to delete this quiz\n t : to manage tags for this quiz\n i : to change instructions \n a : to change availability of this quiz\n h : to change max time\n 0 : to go back to quizzes list\n");
char res;
do {
scanf("%c",&res);
clearBuf();
if(res=='r'){
response_admin(n);
return;
}
else if(res == 'e'){
edit_questions(n);
return;
}
else if(res == 'm'){
if(quizlist.quiz[n].no_of_students_attempted == 0){
if(quizlist.quiz[n].visible != 2){
preview_quiz(n);
change_marks(n);
return;
}
else{
printf("you can't change max marks of questions when it is available to users change the availability and come back.\ntype enter to continue\n");
wait_for_enter();
admin_quizdetails(n);
return;
}
}
else{
printf("you can't change max marks of question once after a user submittes the quiz\ntype enter to continue\n");
wait_for_enter();
admin_quizdetails(n);
return;
}
return;
}
else if(res == 'h'){
printf("Type the new max time\n");
quizlist.quiz[n].max_time = 60 * scanf_int(1000,1);
appdata_save(0);
clearscr();
admin_quizdetails(n);
return;
}
else if(res == 'a'){
clearscr();
printf("Type a corresponding number to change availabilty :\n0 : make quiz invisible\n1 : make only instructions visible\n2 : make users to attempt the quiz\n");
quizlist.quiz[n].visible = scanf_int(2,0);
appdata_save(0);
printf("availability updated successfully\nType ENTER to continue\n");
wait_for_enter();
admin_quizdetails(n);
return;
}
else if(res == 'i'){
add_instrucion_page(n);
admin_quizdetails(n);
return;
}
else if(res == '0'){
showqlist_admin();
return;
}
else if(res == 'p'){
preview_all_questions(n);
return;
}
else if (res == 'c'){
change_max_attempts(n);
return;
}
else if(res == 't'){
if(num !=0){
tag_quiz(n);
return;
}
else{
printf("No tags available currently\nTo create a tag first\ntype ENTER to continue.\n");
wait_for_enter();
admin_quizdetails(n);
return;
}
}
else if(res == 'd'){
printf("Type your password\nType a wrong password to cancel deletion\n");
char resp[14];
smart_fgets(resp,14,stdin);
if(strcmp(currentuser.password,resp) == 0 ){
delete_quiz(n);
return;
}
else{
admin_quizdetails(n);
return;
}
}
else printf("%sNot a valid response try again%s\n", red, normal);
}while(1);
}
void showqlist_admin(){
appdata_read();
clearscr();
printf("type a number to veiw/edit quiz or type '0' to create a quiz\npress '-1' to go back to welcome page\n" );
for (int i = 0; i < quizlist.no_of_quizes; i++) printf("%d : %s\t no.of students attempted %d\n",i+1,quizlist.quiz[i].name,quizlist.quiz[i].no_of_students_attempted);
printf("0 : Create a quiz\n");
int res;
do {
scanf("%d",&res);
clearBuf();
if(res==0){
if(quizlist.no_of_quizes < max_quizes){
addquiz();
}
else{
printf("can't add more than %d quizzes\ntype ENTER to continue\n",max_quizes);
wait_for_enter();
showqlist_admin();
}
}
else if(res>0 && res <= quizlist.no_of_quizes){
admin_quizdetails(res-1);
return;
}
else if(res == -1) return;
else {
printf("%sNot a valid response try again%s\n", red, normal);
res = -2;
}
}while(res <-1 || res> quizlist.no_of_quizes );
}
void delete_user(int id){
if(id != 0){
printf("are you sure to delete this user?(y/n)\n");
char res = takeyorno();
if(res == 'y'){
int auth = authenticate();
if(auth == 1){
for (int mem = id; mem < no_of_currentusers-1; mem++){
userlist[mem] = userlist[mem+1]; //have to change responses too
for (int quiz_id = 0; quiz_id < quizlist.no_of_quizes; quiz_id++)
{
quizes_attempted[mem][quiz_id] = quizes_attempted[mem+1][quiz_id];
for (int ques_id = 0; ques_id < max_q_per_quiz; ques_id++)
{
for (int alt_id = 0; alt_id < max_alternative_q; alt_id++)
{
response[mem][quiz_id][ques_id][alt_id] = response[mem+1][quiz_id][ques_id][alt_id];
}
}
}
}
no_of_currentusers--;
appdata_save(1);
printf("User deleted Type ENTER to go back\n");
wait_for_enter();
clearscr();
view_userlist();
return;
}
else{
clearscr();
view_user(id);
}
}
else{
clearscr();
view_user(id);
}
}
else{
printf("you can't able to delete this account by default\npress enter to continue\n");
wait_for_enter();
clearscr();
view_user(id);
}
}
void rmvtag_user(int id){
clearscr();
for (int i = 0; i < max_tags; i++){
if(userlist[id].tags[i] == 1) printf("%d.%s\n",i+1,taglist[i]);
}
printf("Type the corresponding number to remove the tag\n");
int response = scanf_int(max_tags,1);
printf("Are you sure to remove this tag for the user?(y/n)\n");
char resp = takeyorno();
if(resp == 'y'){
userlist[id].tags[response-1] = 0;
appdata_save(1);
printf("tag removed successfully type ENTER to go back\n");
wait_for_enter();
clearscr();
view_user(id);
}
else{
clearscr();
view_user(id);
}
}
void view_user(int id){
if(userlist[id].type == 1) printf("username :\n%s\npassword :\n%s\nType :\nAdmin\n\nType 1 to edit password for this user\n-1 to delete user\n 0 to goback.\n",userlist[id].username,userlist[id].password);
else if(userlist[id].type == 0) { printf("username :\n%s\npassword :\n%s\nType :\nUser\n\nTags :\n",userlist[id].username,userlist[id].password);
for (int i = 0; i < max_tags; i++){
if(userlist[id].tags[i] == 1) printf("%s\n",taglist[i]);
}
printf("\nType 2 to add tags for this user\nType 1 to edit password for this user\n-1 to delete user\n-2 to a remove tag for the user\n0 to goback.\n");
}
int response = scanf_int(2,-2);
if(response == 1){
take_password(id);
clearscr();
appdata_save(1);
view_user(id);
}
else if(response == 0){
clearscr();
view_userlist();
}
else if(response == 2){
tag_user(id);
clearscr();
appdata_save(1);
view_user(id);
}
else if (response == -2){
rmvtag_user(id);
}
else{
delete_user(id);
}
}
void add_user(){
printf("Type new Username :\n");
char resp[16];
smart_fgets(resp,18,stdin);
for (int id = 0; id < no_of_currentusers; id++){
if (strcmp(resp,userlist[id].username)==0){
printf("This username already exists\ntry again\n");
add_user();
return;
}
}
strcpy( userlist[no_of_currentusers].username,resp);
printf("type account type(0 for user and 1 for admin)\n");
userlist[no_of_currentusers].type = scanf_int(1,0);
for(int i = 0;i < max_tags;i++){
userlist[no_of_currentusers].tags[i] = 0; //initializing tags for the new user.
}
if(taglist[0][0]!= '\0' && userlist[no_of_currentusers].type == 0){
printf("Add tags for this user?y/n\n");
char resp = takeyorno();
if(resp == 'y'){
tag_user(no_of_currentusers);
}
}
take_password(no_of_currentusers);
for (int qid = 0; qid < quizlist.no_of_quizes; qid++){
for (int ques_id = 0; ques_id < quizlist.quiz[qid].no_of_questions; ques_id++){
for (int alt_id = 0; alt_id < max_alternative_q; alt_id++)
{
response[no_of_currentusers][qid][ques_id][alt_id].status = question[qid][ques_id][alt_id].status;
response[no_of_currentusers][qid][ques_id][alt_id].answer[0] = '\0';
}
}
for(int attempt=0;attempt < quizlist.quiz[qid].no_of_max_attempts;attempt++){
quizes_attempted[no_of_currentusers][qid].attempt[attempt].result.attempted = 0;
quizes_attempted[no_of_currentusers][qid].attempt[attempt].result.correct = 0;
quizes_attempted[no_of_currentusers][qid].attempt[attempt].result.incorrect=0;
quizes_attempted[no_of_currentusers][qid].attempt[attempt].result.score= 0;
}
quizes_attempted[no_of_currentusers][qid].no_attempts = 0;
}
no_of_currentusers++; //incrementing no.of current users
appdata_save(1);
clearscr();
view_userlist();
}
void take_password(int id){
printf("Type new password for the user:\n");
char resp[18];
smart_fgets(resp,18,stdin);
printf("conform password:\n");
char resp2[18];
smart_fgets(resp2,18,stdin);
if(strcmp(resp,resp2)==0){
printf("password created/changed successfully\nType Enter to go back\n");
strcpy(userlist[id].password,resp);
wait_for_enter();
}
else{