fork download
  1. program StudentStatsWithData;
  2. uses math;
  3.  
  4. const
  5. TOTAL_STUDENTS = 24;
  6. { ご提示いただいた実際のデータ(24人分) }
  7. RAW_DATA: array[0..TOTAL_STUDENTS - 1] of Integer = (
  8. 42, 48, 50, 50, 51, 73, 64, 77, 74, 90,
  9. 48, 43, 57, 55, 94, 41, 38, 52, 44, 68,
  10. 71, 74, 78, 81
  11. );
  12.  
  13. var
  14. Scores: array[0..TOTAL_STUDENTS - 1] of Integer;
  15. I, J, Temp, PassCount: Integer;
  16. Sum, Average, Variance, StdDev, Median: Real;
  17.  
  18. begin
  19. { 1. 定数配列から作業用配列へデータをコピー }
  20. Sum := 0;
  21. PassCount := 0;
  22. for I := 0 to TOTAL_STUDENTS - 1 do
  23. begin
  24. Scores[I] := RAW_DATA[I];
  25. Sum := Sum + Scores[I];
  26. if Scores[I] >= 60 then
  27. PassCount := PassCount + 1;
  28. end;
  29.  
  30. { 2. 基本統計量の計算 }
  31. Average := Sum / TOTAL_STUDENTS;
  32.  
  33. { 3. 中央値を求めるためのソート(バブルソート) }
  34. for I := 0 to TOTAL_STUDENTS - 2 do
  35. for J := 0 to TOTAL_STUDENTS - 2 - I do
  36. if Scores[J] > Scores[J + 1] then
  37. begin
  38. Temp := Scores[J];
  39. Scores[J] := Scores[J + 1];
  40. Scores[J + 1] := Temp;
  41. end;
  42.  
  43. { 最高点と最低点はソート後の配列の両端から取得 }
  44. { (Scores配列は昇順に並び替えられています) }
  45. if TOTAL_STUDENTS mod 2 <> 0 then
  46. Median := Scores[TOTAL_STUDENTS div 2]
  47. else
  48. Median := (Scores[(TOTAL_STUDENTS div 2) - 1] + Scores[TOTAL_STUDENTS div 2]) / 2.0;
  49.  
  50. { 4. 標準偏差の計算 }
  51. Variance := 0;
  52. for I := 0 to TOTAL_STUDENTS - 1 do
  53. Variance := Variance + Sqr(Scores[I] - Average);
  54. Variance := Variance / TOTAL_STUDENTS;
  55. StdDev := Sqrt(Variance);
  56.  
  57. { 5. 結果の出力 }
  58. WriteLn('==================================');
  59. WriteLn('【集計結果(実際のデータ 24人分)】');
  60. WriteLn('==================================');
  61. WriteLn('平均点 : ', Average:0:2);
  62. WriteLn('中央値 : ', Median:0:1);
  63. WriteLn('最高点 : ', Scores[TOTAL_STUDENTS - 1]);
  64. WriteLn('最低点 : ', Scores[0]);
  65. WriteLn('標準偏差 : ', StdDev:0:2);
  66. WriteLn('合格者数 : ', PassCount, ' 人 / ', TOTAL_STUDENTS, ' 人');
  67. WriteLn('----------------------------------');
  68.  
  69. { 6. 各学生の偏差値を出力(点数の高い順に見やすく表示) }
  70. WriteLn('【各学生の点数と偏差値(降順)】');
  71. for I := TOTAL_STUDENTS - 1 downto 0 do
  72. begin
  73. if StdDev = 0 then
  74. WriteLn('点数: ', Scores[I]:2, ' -> 偏差値: 50.0')
  75. else
  76. WriteLn('点数: ', Scores[I]:2, ' -> 偏差値: ', (10 * (Scores[I] - Average) / StdDev + 50):0:1);
  77. end;
  78. WriteLn('==================================');
  79.  
  80. ReadLn; { 画面を閉じずに一時停止 }
  81. end.
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
==================================
【集計結果(実際のデータ 24人分)】
==================================
平均点   : 60.96
中央値   : 56.0
最高点   : 94
最低点   : 38
標準偏差 : 16.11
合格者数 : 11 人 / 24 人
----------------------------------
【各学生の点数と偏差値(降順)】
点数: 94 -> 偏差値: 70.5
点数: 90 -> 偏差値: 68.0
点数: 81 -> 偏差値: 62.4
点数: 78 -> 偏差値: 60.6
点数: 77 -> 偏差値: 60.0
点数: 74 -> 偏差値: 58.1
点数: 74 -> 偏差値: 58.1
点数: 73 -> 偏差値: 57.5
点数: 71 -> 偏差値: 56.2
点数: 68 -> 偏差値: 54.4
点数: 64 -> 偏差値: 51.9
点数: 57 -> 偏差値: 47.5
点数: 55 -> 偏差値: 46.3
点数: 52 -> 偏差値: 44.4
点数: 51 -> 偏差値: 43.8
点数: 50 -> 偏差値: 43.2
点数: 50 -> 偏差値: 43.2
点数: 48 -> 偏差値: 42.0
点数: 48 -> 偏差値: 42.0
点数: 44 -> 偏差値: 39.5
点数: 43 -> 偏差値: 38.9
点数: 42 -> 偏差値: 38.2
点数: 41 -> 偏差値: 37.6
点数: 38 -> 偏差値: 35.8
==================================