#include<stdio.h>
#include<conio.h>
int main()
{ FILE *stud_file;
FILE *answer_file;
answer_file=fopen("c:\\answer.dat","r");
int studnum,aa=0,bb=0,cc=0,dd=0,blank=0,aaa=0,bbb=0,ccc=0,ddd=0,bblank=0,aaaa=0,bbbb=0,cccc=0,dddd=0,bbblank=0;
char name[20];
char sname[20];
char studans[50];
char booktype;
char correctans[50];
int dogru=0,yanlis=0;
float grade;
int maxa=0,maxb=0,maxc=0;
char ahiname[20],ahisname[20],bhiname[20],bhisname[20],chiname[20],chisname[20];
int ahinumber,bhinumber,chinumber;
printf("Student Student Correct Wrong Total\n");
printf("Number Name and Last Name Answer Answer Grade\n");
do
{stud_file=fopen("c:\\booklet.dat","r");
fscanf(answer_file,"%d %s %s %s",&studnum,&studans,&name,&sname);
if(studans[0]=='A')
{ for(int y=0;y<1;y++)
{fscanf(stud_file,"%s",&correctans);}
}
else if(studans[0]=='B')
{
for(int i=0;i<2;i++)
{
fscanf(stud_file,"%s",&correctans);
}
}
else if(studans[0]=='C')
{
for(int j=0;j<3;j++)
{
fscanf(stud_file,"%s",&correctans);
}
}
for(int cnt=1;cnt<51;cnt++)
{ if((studans[cnt]=='*')||(correctans[cnt]=='*')){continue;}
if(studans[cnt]==correctans[cnt])
{
dogru++;
}
else
{
yanlis++;
}
}
grade=(dogru*2)-(yanlis*0.25);
printf("%d\t %s %s\t\t %d\t\t%d\t%f\n",studnum,name,sname,dogru,yanlis,grade);
if(studans[0]=='A')
{
if(maxa<grade)
{
maxa=grade;
for(int p=0;p<21;p++)
{
ahiname[p]=name[p];
}
for(int z=0;z<21;z++)
{
ahisname[z]=sname[z];
}
ahinumber=studnum;
}
else {maxa=maxa;}
}
if(studans[0]=='B')
{
if(maxb<grade)
{maxb=grade;
for(int p=0;p<20;p++)
{
bhiname[p]=name[p];
}
for(int n=0;n<20;n++)
{
bhisname[n]=sname[n];
}
bhinumber=studnum;
}
else {maxb=maxb;}
}
if(studans[0]=='C')
{
if(maxc<grade)
{maxc=grade;
for(int p=0;p<21;p++)
{
chiname[p]=name[p];
}
for(int m=0;m<21;m++)
{
chisname[m]=sname[m];
}
chinumber=studnum;
}
else {maxc=maxc;}
}
dogru=0;yanlis=0;grade=0.0;
fclose(stud_file);
}while(feof(answer_file)==0);
fclose(answer_file);
fclose(stud_file);
printf("\n\n");
printf("%d %s %s Booklet A Got the highest grade in this group \n",ahinumber,ahiname,ahisname);
printf("%d %s %s Booklet B Got the highest grade in this group \n",bhinumber,bhiname,bhisname);
printf("%d %s %s Booklet C Got the highest grade in this group \n",chinumber,chiname,chisname);
return(0);
}