/* データファイル(Pro2-15)には模試の成績が書かれている。各行のデータは左から順に 受験番号、英語の得点、数学の得点、国語の得点、社旗の得点、の順に並んでいる。 受験番号を入力したら各科目の点数、5科目の合計点、 そのそれぞれに対する偏差値を表示するプログラムを書きなさい。 */ #include #include #include int main() { int sum; int number; double x; int sum_eng=0,sum_math=0,sum_koku=0,sum_sci=0,sum_soc=0; double ave_eng,ave_math,ave_koku,ave_sci,ave_soc; int gaku; double pow_eng,pow_math,pow_koku,pow_sci,pow_soc; double sum_p_eng=0,sum_p_math=0,sum_p_koku=0,sum_p_sci=0,sum_p_soc=0; int math,eng,koku,sci,soc; double hensa_eng,hensa_math,hensa_koku,hensa_sci,hensa_soc; double bun_eng,bun_math,bun_koku,bun_sci,bun_soc; int eng2,math2,koku2,sci2,soc2; double hen_eng,hen_math,hen_koku,hen_sci,hen_soc; int sum2; double sum_z=0; double ave_sum=0,pow_sum=0,sum_p_sum=0,hensa_sum=0,bun_sum=0,hen_sum=0,sum_sum=0; FILE *fp; fp=fopen("test.dat","r"); if(fp==NULL){ printf("ファイルが開けません\n"); exit(1); } x=0; sum=0; printf("受験番号を入力してください : "); scanf("%d",&number); while(fscanf(fp,"%d %d %d %d %d %d",&gaku,&eng,&math,&koku,&sci,&soc)!=EOF){ if(number==gaku){ eng2=eng; math2=math; koku2=koku; sci2=sci; soc2=soc; sum=eng+math+koku+sci+soc; sum2=sum; fclose(fp); fp=fopen("test.dat","r"); if(fp==NULL){ printf("ファイルが開けません\n"); exit(1); } while(fscanf(fp,"%d %d %d %d %d %d",&gaku,&eng,&math,&koku,&sci,&soc)!=EOF){ sum_eng+=eng; sum_math+=math; sum_koku+=koku; sum_sci+=sci; sum_soc+=soc; sum_z=eng+math+koku+sci+soc; sum_sum+=sum_z; pow_eng=pow(eng,2); pow_math=pow(math,2); pow_koku=pow(koku,2); pow_sci=pow(sci,2); pow_soc=pow(soc,2); pow_sum=pow(sum_z,2); sum_p_eng+=pow_eng; sum_p_math+=pow_math; sum_p_koku+=pow_koku; sum_p_sci+=pow_sci; sum_p_soc+=pow_soc; sum_p_sum+=pow_sum; x++; } } } ave_eng=sum_eng/x; ave_math=sum_math/x; ave_koku=sum_koku/x; ave_sci=sum_sci/x; ave_soc=sum_soc/x; ave_sum=sum_sum/x; bun_eng=(sum_p_eng/x) - (pow(ave_eng,2)); bun_math=(sum_p_math/x) - (pow(ave_math,2)); bun_koku=(sum_p_koku/x) - (pow(ave_koku,2)); bun_sci=(sum_p_sci/x) - (pow(ave_sci,2)); bun_soc=(sum_p_soc/x) - (pow(ave_soc,2)); bun_sum=(sum_p_sum/x) - (pow(ave_sum,2)); hensa_eng=sqrt(bun_eng); hensa_math=sqrt(bun_math); hensa_koku=sqrt(bun_koku); hensa_sci=sqrt(bun_sci); hensa_soc=sqrt(bun_soc); hensa_sum=sqrt(bun_sum); hen_eng= 50 + ( (eng2 - ave_eng)/hensa_eng * 10); hen_math= 50 + ( (math2 - ave_math)/hensa_math *10); hen_koku= 50 + ( (koku2 - ave_koku)/hensa_koku *10); hen_sci= 50 + ( (sci2 - ave_sci)/hensa_sci * 10); hen_soc= 50 + ( (soc2 - ave_soc)/hensa_soc * 10); hen_sum= 50 + ( (sum2 - ave_sum)/hensa_sum * 10); printf("英語の得点は %d 点です(偏差値 = %2.1f)\n",eng2,hen_eng); printf("数学の得点は %d 点です(偏差値 = %2.1f)\n",math2,hen_math); printf("国語の得点は %d 点です(偏差値 = %2.1f)\n",koku2,hen_koku); printf("理科の得点は %d 点です(偏差値 = %2.1f)\n",sci2,hen_sci); printf("社会の得点は %d 点です(偏差値 = %2.1f)\n",soc2,hen_soc); printf("合計点は %d 点です(偏差値 = %2.1f)\n",sum2,hen_sum); return 0; }