-
Notifications
You must be signed in to change notification settings - Fork 0
/
final ratespiel.c
1632 lines (1586 loc) · 50.4 KB
/
final ratespiel.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<stdio.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#include <windows.h>
#include"instructions.h"
void displayscore(int);
void que(char *);
void mainmenu();
typedef struct user
{
char unm[10];
char up[10];
char name[20];
char mail[30];
char mno[10];
}USR;
typedef struct mrk
{
char usernm[20];
float sc;
float t;
int pc;
int nc;
}MRK;
MRK m;
FILE *fs,*f;
USR u;
int search(char *id)
{
char nm[10];
int pos;
rewind(fs);
while(1)
{
fread(&u,sizeof(USR),1,fs);
if(feof(fs))
{
pos=-1;
break;
}
if(strcmp(u.unm,id)==0)
break;
pos=ftell(fs);
}
return pos;
}
int searchloginid(char *id,char *p)
{
char nm[10];
int pos;
rewind(fs);
while(1)
{
fread(&u,sizeof(USR),1,fs);
if(feof(fs))
{
pos=-1;
break;
}
if(strcmp(u.unm,id)==0 && strcmp(u.up,p)==0)
break;
pos=ftell(fs);
}
return pos;
}
void signup()
{
char nm[10],p[15];
char pn[10],gm[30],name[20];;
int pos,i=0,j=0,k,cnt=0;
while(1)
{
printf("\n");
for(k=0;k<70;k++)
printf("***");
printf("\n\n\t\t\t\t\t\t\t\t\t\t\t** SIGN UP SECTION **");
printf("\n\t\t\t\t\t\t\t\t\t\t\t =================");
printf("\n\n");
while(1)
{
printf("\n\t* Enter Student Name:\n\t ");
fflush(stdin);
scanf("%[^\n]s",name);
printf("\n");
for(k=0;k<70;k++)
printf("---");
j=0;
while(j<=strlen(name))
{
if((name[j]>=65 &&name[j]<=90)||(name[j]>=97 &&name[j]<=122)||name[j]==32)
j++;
else
break;
}
if(j!=strlen(name))
{
printf("\n\tInvalid Student Name.....Please try again\n");
}
else
break;
}
while(1)
{
printf("\n\t* Enter your Email address:\n\t ");
fflush(stdin);
scanf("%s",gm);
printf("\n");
for(k=0;k<70;k++)
printf("---");
if((gm[0]<65 || gm[0]>90)&&(gm[0]<97|| gm[0]>122))
{
printf("\n\tInvalid E-Mail.....Please try again\n");
continue;
}
j=0;
while(j<=strlen(gm))
{
if(gm[j]=='@')
{
break;
}
j++;
}
if(j<=strlen(gm))
{
break;
}
else
printf("\n\tInvalid E-Mail.....Please try again\n");
}
while(1)
{
printf("\n\t* Enter your mobile no:\n\t ");
fflush(stdin);
scanf("%s",pn);
printf("\n");
for(k=0;k<70;k++)
printf("---");
if(pn[0]<'7')
{
printf("\n\tInvalid Mobile number...Please try again");
continue;
}
j=0;
if(strlen(pn)>10 || strlen(pn)<10)
{
printf("\n\tInvalid Mobile number...Please try again");
continue;
}
else
{
while(j<10)
{
if(pn[j]>=48 && pn[j]<=57)
j++;
else
break;
}
}
if(j==10)
break;
else
printf("\n\tInvalid Mobile number...Please try again");
}
printf("\n\t* Enter Student's User Name\n\t ");
fflush(stdin);
scanf("%s",nm);
printf("\n");
for(k=0;k<70;k++)
printf("---");
pos=search(nm);
if(pos>=0)
{
printf("\n\tThis account is already registered");
printf("\n\tPlease log in to start your exam\n\n");
break;
}
//fflush(stdin);
while(1)
{
fflush(stdin);
i=0;
cnt=0;
printf("\n\t* Student's Password:\n\t ");
do{
p[i]=getch();
if(p[i]!='\r')
{
if(p[i]==8)
{
i--;
printf("\b \b");
continue;
}
printf("*");
}
i++;
cnt++;
}while(p[i-1]!='\r');
p[i-1]='\0';
if(cnt<6)
{
printf("\n\tToo short Password.....Please try again\n");
}
else
{
if(cnt>10)
{
printf("\n\tToo long Password.....Please try again\n");
}
else
break;
}
}
printf("\n");
for(k=0;k<70;k++)
printf("---");
strcpy(u.unm,nm);
strcpy(u.up,p);
strcpy(u.name,name);
strcpy(u.mail,gm);
strcpy(u.mno,pn);
fwrite(&u,sizeof(USR),1,fs);
printf("\n\n\t\t\tSuccessfully Registration of Student");
printf("\n\n\t\t\tPlease \"Log In\" for Entering QUIZ");
printf("\n\n\t\t\t\tPress \"ENTER\" to continue...");
break;
}
}
void home()
{
int cnt,i;
char opt;
system("cls");
for(i=0;i<70;i++)
printf("===");
printf("\n\n\t\t\t\t\t\t\t\t\t***Welcome To RATESPIEL:A Programming Quiz***\n\n");
for(i=0;i<70;i++)
printf("===");
puts("\n\n\t\t\t\t * Enter 'V' to view LEADERBOARD ");
puts("\n\n\t\t\t\t * Enter 'H' for HELP ");
puts("\n\n\t\t\t\t * Enter 'Q' to QUIT ");
for(i=0;i<70;i++)
printf("---");
printf("\n\n\t\t\t\tOption:");
opt=(toupper(getch()));
{
while(1)
{
switch(opt)
{
case 'V':
{
system("cls");
cnt=getcount();
displayscore(cnt);
getch();
home();
break;
}
case 'H':
{
system("cls");
help2();
home();
break;
}
case 'Q':
{
mainmenu();
break;
}
}
}
}
}
void login()
{
char nm[10],p[10],opt;
int pos,i=0,k;
while(1)
{
printf("\n");
for(k=0;k<70;k++)
printf("***");
printf("\n\n\t\t\t\t\t\t\t\t\t\t\tLOG IN SECTION");
printf("\n\t\t\t\t\t\t\t\t\t\t\t===============");
printf("\n\n\n\t* Enter student's user name:\n\t ");
scanf("%s",nm);
for(k=0;k<70;k++)
printf("---");
printf("\n\n\n\t* Student's Password:\n\t");
do{
p[i]=getch();
if(p[i]!='\r')
{
if(p[i]==8)
{
i--;
printf("\b \b");
continue;
}
printf("*");
}
i++;
}while(p[i-1]!='\r');
p[i-1]='\0';
pos=searchloginid(nm,p);
printf("\n");
for(k=0;k<70;k++)
printf("---");
if(pos<0)
{
printf("\n\n\t\t\t Incorrect Username or Password or This Student is not registered for Exam\n");
printf("\n\t\t\tPlease enter correct Username or Password or Please Singup to register for Exam.\n\n");
break;
}
printf("\n\n\t\t\tThank you..!!\n\n\t\t\tYou have been Successfully login\n\n");
printf("\n\n\n\t\t\t\t\t\t\t\t\tPlease press 'ENTER' to continue...!");
getch();
system("cls");
instone();
getch();
system("cls");
printf("\n\t\t\t\t\t\t\t\t\t **** WELCOME TO RATESPIEL THE PROGRAMMING TEST****\n");
printf("\t\t\t\t\t\t\t\t\t -------------------------------------------");
printf("\n\n");
for(k=0;k<70;k++)
printf("===");
puts("\n\n\n\t\t\t\t\t\t\t\t\t\t\t Enter 'S' to START TEST");
opt=(toupper(getch()));
if(opt=='S')
{
que(u.unm);
getch();
home();
}
break;
}
}
void display()
{
int i,j=0;
rewind(fs);
for(i=0;i<70;i++)
printf("===");
printf("\n\n\t\t\t\t\t\t\t\t\t\t\t\t***STUDENTS DETAILS***\n\t\t\t\t\t\t\t\t\t\t\n\n");
for(j=0;j<70;j++)
printf("---");
printf("\n\t\t\tSr.No\t\tUSER ID\t\t\t\tPASSWORD\t\t\tNAME\t\t\t\tMAIL ID\t\t\t\tMOBILE NO\n");
for(j=0;j<70;j++)
printf("---");
i=1;
while(1)
{
fread(&u,sizeof(USR),1,fs);
if(feof(fs))
break;
printf("\n\t\t\t %d.\t\t %-30s %-30s%-30s%-30s\t%-30s\n",i,u.unm,u.up,u.name,u.mail,u.mno);
i++;
}
for(j=0;j<70;j++)
printf("===");
}
void writescore(char *nm,float score,int pcnt,int ncnt,float treq)
{
float sc;
char n[20];
int i=0,j=0;
FILE *f;
f=fopen("myscore.dat","a+b");
if(f==NULL)
{
f=fopen("myscore.dat","wb");
fclose(f);
f=fopen("myscore.dat","a+b");
}
strcpy(m.usernm,nm);
sc=score;
m.sc=sc;
m.pc=pcnt;
m.nc=ncnt;
m.t=treq;
fwrite(&m,sizeof(MRK),1,f);
fclose(f);
return;
}
int getcount()
{
int i=0,j=0,pos=0,tmp=0,d=0,cnt=0;
rewind(f);
f=fopen("myscore.dat","rb");
while(1)
{
fread(&m,sizeof(MRK),1,f);
if(feof(f))
break;
cnt++;
}
return cnt;
}
void displayscore(int cnt)
{
int no;
int i=0,d=0,pos=0,tmp=0,j=0,k=0,apc[cnt],anc[cnt],tmp1=0,tmp2=0,tmp3=0;
float ac[cnt],atc[cnt];
char uname[cnt][15];
f=fopen("myscore.dat","rb");
if(f==NULL)
{
printf("\n\n\n\n\t\t\tNo records found");
getch();
return;
}
while(1)
{
fread(&m,sizeof(m),1,f);
if(feof(f))
{
break;
}
ac[i]=m.sc;
strcpy(uname[i],m.usernm);
apc[i]=m.pc;
anc[i]=m.nc;
atc[i]=m.t;
if(i==cnt)
break;
else
i++;
}
char tmpStr[15];
d=cnt;
for(i=0;i<d-1;i++)
{
pos=i;
for(j=i+1;j<d;j++)
{
if(ac[j]>ac[pos])
pos=j;
}
if(i!=pos)
{
tmp=ac[i];
strcpy(tmpStr,uname[i]);
tmp1=apc[i];
tmp2=anc[i];
tmp3=atc[i];
ac[i]=ac[pos];
strcpy(uname[i],uname[pos]);
apc[i]=apc[pos];
anc[i]=anc[pos];
atc[i]=atc[pos];
ac[pos]=tmp;
strcpy(uname[pos],tmpStr);
apc[pos]=tmp1;
anc[pos]=tmp2;
atc[pos]=tmp3;
}
}
for(k=0;k<70;k++)
printf("===");
printf("\n\n\t\t\t\t\t\t\t\t\t\t\t ***STUDENT'S LEADERBOARD***\n\t\t\t\t\t\t\t\t\t\t\n\n");
for(k=0;k<70;k++)
printf("---");
printf("\n\t\tUSER ID\t\t\t\tPOSITIVE QUESTIONS\t\t\tNEGATIVE QUESTIONS\t\t\tSCORE\t\t\tTIME REQUIRED\t\t\tRANK\n");
for(k=0;k<70;k++)
printf("---");
for( i=0;i<cnt;i++)
{
printf("\n\t\t %-10s\t\t\t\t%-5d \t\t\t\t\t %-5d\t\t\t\t%-5.3f\t\t\t %-5.3f\t\t\t %-5d\n",uname[i],apc[i],anc[i],ac[i],atc[i],i+1);
}
for(k=0;k<70;k++)
printf("===");
fclose(f);
return;
}
void que(char *nm)
{
int i,j,pcnt=0,ncnt=0,r1,r2,cnt=0,pcnt1=0,ncnt1=0;
float score=0,marks=0,totmrk=0,treq=0,treq1=0;
char opt,snm[20],ans;
strcpy(snm,nm);
time_t time1,time2,time3,time4;
time(&time1);
for(i=0;i<=8;i++)
{
system("cls");
r1=i;
switch(r1)
{
case 1:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t1.who is the founder of C language ?");
printf("\n\n\t\ta.Charls Babge b.Denis Richie");
printf("\n\t\tc.Steve Jobs d.Bill Gets");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='B')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();
break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option b.Denis Richie\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 2:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t2.What will be the output of following program?");
printf("\n\t\t#include<stdio.h>\n\t\tvoid main()\n\t\t{\n\t\t\tint i = 10;\n\t\t\tstatic int x = i;\n\t\t\tif (x == i)\n\t\t\t\tprintf(\"equal\");\n\t\t\telse if (x < i)))\n\t\t\t\tprintf(\"less than\");\n\t\t\telse\n\t\t\t\tprintf(\"greater than\");\n\t\t}");
printf("\n\t\tOptions:\n\t\ta.equal\n\t\tb.greater than\n\t\tc.less than\n\t\td.compiler error\n\t\te.none of the above");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='D')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option d.compiler error\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 3:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t3.What will be output if you will compile and execute the following c code?");
printf("\n\t\t#include <stdio.h>\n\t\tint main()\n\t\t{\n\t\t\tint a = 5;\n\t\t\tfloat b;\n\t\t\tprintf(\"%%d \", sizeof(++a + b));\n\t\t\tprintf(\"%%d \", a);\n\t\t\treturn 0;\n\t\t} ");
printf("\n\t\tOptions:\n\t\ta. 2 6\n\t\tb. 4 6\n\t\tc. 2 5\n\t\td. 4 5");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='D')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option d. 4 5\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 4:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t4.What will be the output of following program?");
printf("\n\t\t#include<stdio.h>\n\t\tvoid main()\n\t\t{\n\t\t\tprintf(\"\%%s\", \"i\"\n\t\t\t\t\"am\"\n\t\t\t\t\"good\");\n\t\t}");
printf("\n\t\tOptions:\n\t\ta. i am good\n\t\tb. i\n\t\tc. good\n\t\td. iamgood\n\t\te. Compiler error");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='D')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option d.iamgood\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();
break;
}
case 5:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t5.What is the output of following program?");
printf("\n\t\t#include <stdio.h>\n\t\tint main()\n\t\t{\n\t\t\tif (0)\n\t\t\t;\n\t\t\tprintf(\"Hello\");\n\t\t\tprintf(\"Hi\");\n\t\t\treturn 0;\n\t\t} ");
printf("\n\t\tOptions:\n\t\ta. Hi\n\t\tb. HelloHi\n\t\tc. run time error\n\t\td. None of the mentioned");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='B')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option b. HelloHi\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 6:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t6.Which of the following true about FILE *fp ?");
printf("\n\t\tOptions:\n\t\ta. FILE is a keyword in C for representing files and fp is a variable of FILE type.");
printf("\n\t\tb. FILE is a structure and fp is a pointer to the structure of FILE type.");
printf("\n\t\tc. FILE is a stream");
printf("\n\t\td. FILE is a buffered stream.");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='B')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option b.FILE is a structure and fp is a pointer to the structure of FILE type.\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 7:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t7.In fopen(), the open mode \"wx\" is sometimes preferred \"w\" because.");
printf("\n\n\t\t1) Use of wx is more efficient.\n\t\t2) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists.");
printf("\n\t\tOptions:\n\t\t a.Only 1\n\t\tb. Only 2\n\t\tc. Both 1 and 2\n\t\td. Neither 1 nor 2");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='B')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option b.Only 2\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 8:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t8.Which of the following functions from \"stdio.h\" can be used in place of printf()?");
printf("\n\t\tOptions:\n\t\ta. fputs() with FILE stream as stdout.\n\t\tb. fprintf() with FILE stream as stdout.\n\t\tc. fwrite() with FILE stream as stdout.\n\t\td. All of the above three a, b and c.\n\t\te. In \"stdio.h\", there's no other equivalent function of printf().");
printf("\n\n\t\tRight Your ans Here:");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPress 'Q' for QUIT the exam");
ans=toupper(getch());
if(ans=='Q')
{
system("cls");
time(&time2);
treq=difftime(time2, time1);
marks=(float)pcnt*3-1*ncnt-difftime(time2, time1)/180;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\t\t\t\t\t\t\tYour TOTAL score is %5.3f",totmrk);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='B')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option b.fprintf() with FILE stream as stdout\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
}
}
system("cls");
time(&time2);
treq=difftime(time2, time1);
pcnt1=pcnt;
ncnt1=ncnt;
score=(float)3*pcnt-ncnt-difftime(time2, time1)/180;
printf("\n\n\n\n\n");
for(i=0;i<70;i++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\t\t\t\t\t\t\tYour score in Level 1 is %5.3f",score);
printf("\n\n\n\n\t\t\t\t\t\t\tPlease press 'ENTER' to continue....\n\n\n\n\n\n\n\n\n");
for(i=0;i<70;i++)
printf("===");
getch();
if(score>=10)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tCongratulation Mr/Miss \"%s\" are done with LEVEL 1..!!! And you are selected for LEVEL 2\n\n\n\t\t\t\t\t\t\t\t\tPress any key for LEVEL 2 or press 'S' for submit test",nm);
if(toupper(getch())=='S')
{
totmrk=(float)score+marks;
writescore(snm,totmrk,pcnt,ncnt,treq);
getch();
return home();
}
else
{
pcnt=0,ncnt=0;
system("cls");
printf("\n");
for(i=0;i<70;i++)
printf("===");
printf("\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t****Welcome to Level 2****");
insttwo();
getch();
time(&time3);
for(i=0;i<=10;i++)
{
system("cls");
r2=i;
switch(r2)
{
case 1:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t1.What is the output of following program?");
printf("\n\t\tincludestdio.h\n\t\tint main()\n\t\t{\n\t\t\tstruct site\n\t\t\t{\n\t\t\t\tchar name[] = \"GeeksQuiz\";\n\t\t\t\tint no_of_pages = 200;\n\t\t\t};\n\t\t\tstruct site *ptr;\n\t\t\tprintf(\"%%d \", ptr->no_of_pages);\n\t\t\tprintf(\"%%s\", ptr->name);\n\t\t\tgetchar();\n\t\t\treturn 0;\n\t\t} ");
printf("\n\t\tOptions:\n\t\ta. 200 GeeksQuiz\n\t\tb. 200\n\t\tc. Runtime Error\n\t\td. Compiler Error");
printf("\n\n\t\t\t\t* Enter 'E' to skip this question\t\t\t\t\t\t\t\t\t* Press 'Q' for QUIT the exam\n\n");
printf("\n\n\t\tRight Your ans Here:");
ans=toupper(getch());
if(ans=='E')
{
break;
}
if(ans=='Q')
{
system("cls");
time(&time4);
treq1=difftime(time4, time3);
marks=(float)pcnt*5-2*ncnt-difftime(time4, time3)/300;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\tYour score in Level 2 is %5.3f",score);
printf("\n\n\t\t\t\t\t\t\t\t\t\t\tYour Total Score is %5.3f",totmrk);
printf("\n\n\n\t\t\t\t\t\t\t\t\t\t\tPlease press 'ENTER' to continue\n\n\n\n\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
pcnt=pcnt1+pcnt;
ncnt=ncnt1+ncnt;
treq=treq1+treq;
writescore(snm,totmrk,pcnt,ncnt,treq);
return;
}
if(ans=='D')
{
printf("\n\n\t\tRight Answer\n\n");
pcnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
else
{
printf("\n\n\t\tWrong Answer:\n\t\tCorrect Ans is option d.Compiler Error\n\n");ncnt++;
for(j=0;j<70;j++)
printf("---");
getch();break;
}
case 2:
printf("\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t2.What is the output of following program?");
printf("\n\t\t#include<stdio.h>\n\t\tstruct Point\n\t\t{\n\t\t\tint x, y, z;\n\t\t};\n\t\tint main()\n\t\t{\n\t\t\tstruct Point p1 = {.y = 0, .z = 1, .x = 2};\n\t\t\tprintf(\"%%d %%d %%d\", p1.x, p1.y, p1.z);\n\t\t\treturn 0;\n\t\t}");
printf("\n\t\tOptions:\n\t\ta. Compiler Error\n\t\tb. 2 0 1\n\t\tc. 0 1 2\n\t\td. 2 1 0");
printf("\n\n\t\t\t\t* Enter 'E' to skip this question\t\t\t\t\t\t\t\t\t*Press 'Q' for QUIT the exam\n\n");
printf("\n\n\t\tRight Your ans Here:");
ans=toupper(getch());
if(ans=='E')
{
break;
}
if(ans=='Q')
{
system("cls");
time(&time4);
treq1=difftime(time4, time3);
marks=(float)pcnt*5-2*ncnt-difftime(time4, time3)/300;
totmrk=(float)score+marks;
printf("\n\n\n\n\n");
for(j=0;j<70;j++)
printf("===");
printf("\n\n\n\n\t\t\t\tGreat Job Mr/Miss: \"%s\"",nm);
printf("\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\tYour score in Level 2 is %5.3f",score);