int main(int argc, char *argv[]) {
struct HR{
char Sname[10];
int Kscore;
int Escore;
int Mscore;
float Jscore;
int rank;
char G;
};
struct HR C_HR[10];
struct HR T_HR;
FILE *ww;
ww=fopen("d:\\성적기록부.txt","r");
int a;
for(a=0; a<10;a++){
fscanf(ww,"%s%d%d%d", C_HR[a].Sname, &C_HR[a].Kscore, &C_HR[a].Escore, &C_HR[a].Mscore);
C_HR[a].Jscore= (float)((C_HR[a].Kscore+C_HR[a].Escore+C_HR[a].Mscore)/3);
printf("%11s%5d%5d%5d%9.2f\n", C_HR[a].Sname, C_HR[a].Kscore, C_HR[a].Escore, C_HR[a].Mscore, C_HR[a].Jscore);
}
fclose(ww);
/*--------------sorting----------------*/
int i,J,k,p=0;
for(i=0; i<9; i++){
for(J=i+1; J<10; J++){
if(C_HR[i].Jscore>C_HR[J].Jscore){
T_HR=C_HR[i];
C_HR[i]=C_HR[J];
C_HR[J]=T_HR;
}
}
}
printf("\n\n\n");
for( p=0; p<10;p++){
printf("%11s%5d%5d%5d%9.2f\n", C_HR[p].Sname, C_HR[p].Kscore, C_HR[p].Escore, C_HR[p].Mscore, C_HR[p].Jscore);
}
/*--------------ranking-----------------*/
for(i=0; i<10;++i)
{
C_HR[i].rank=1;
}
for(i=0; i<9; i++){
for(J=i+1; J<10; J++){
if(C_HR[i].Jscore<C_HR[J].Jscore){
C_HR[i].rank=C_HR[i].rank+1;
}
}
}
printf("\n\n\n");
for( p=0; p<10;p++){
printf("%11s%5d%5d%5d%9.2f%5d\n", C_HR[p].Sname, C_HR[p].Kscore, C_HR[p].Escore, C_HR[p].Mscore, C_HR[p].Jscore,C_HR[p].rank);
}
/*----------------grade-----------------*/
for(i=0;i<10;i++)
{
if(C_HR[i].Jscore>=90)
{
C_HR[i].G='A';
}
else if((C_HR[i].Jscore<90)&&(C_HR[i].Jscore>=80))
{
C_HR[i].G='B';
}
else if((C_HR[i].Jscore<80)&&(C_HR[i].Jscore>=70))
{
C_HR[i].G='C';
}
else if((C_HR[i].Jscore<70)&&(C_HR[i].Jscore>=60))
{
C_HR[i].G='D';
}
else
{
C_HR[i].G='F';
}
}
printf("\n\n\n");
FILE *ww2;
ww2=fopen("d:\\grade.txt","w");
for(p=9; p>=0;p--){
printf("%5d%11s%5d%5d%5d%9.2f%5c\n",C_HR[p].rank, C_HR[p].Sname, C_HR[p].Kscore, C_HR[p].Escore, C_HR[p].Mscore,C_HR[p].Jscore,C_HR[p].G);
fprintf(ww2, "%5d%11s%5d%5d%5d%9.2f%5c\n",C_HR[p].rank, C_HR[p].Sname, C_HR[p].Kscore, C_HR[p].Escore, C_HR[p].Mscore, C_HR[p].Jscore,C_HR[p].G);
}
fclose(ww2);
return 0;
}