章末問題9−3の解答例 Const 生徒数 As Integer = 5 Const 科目数 As Integer = 3 Dim 成績(生徒数, 科目数) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' 列と行それぞれの合計点と平均点のインデックス番号を定数で定義する Const 合計点の列のインデックス番号 As Integer = 6 Const 平均点の列のインデックス番号 As Integer = 7 Const 合計点の行のインデックス番号 As Integer = 3 Const 平均点の行のインデックス番号 As Integer = 4 Dim i, j, 合計 As Integer For i = 1 To 生徒数 For j = 1 To 科目数 成績(i, j) = Val(成績表(i, j - 1).Value) Next Next For i = 1 To 科目数 合計 = 科目の合計点(i) '合計点の計算はプロシージャ呼び出しで行う 成績表(合計点の列のインデックス番号, i).Value = 合計 成績表(平均点の列のインデックス番号, i).Value = Format(合計 / 生徒数, "0.0") Next For i = 1 To 生徒数 合計 = 生徒の合計点(i) '合計点の計算はプロシージャ呼び出しで行う 成績表(i, 合計点の行のインデックス番号).Value = 合計 成績表(i, 平均点の行のインデックス番号).Value = Format(合計 / 科目数, "0.0") Next End Sub Public Function 科目の合計点(ByVal 科目番号 As Integer) As Double Dim i, 合計 As Integer 合計 = 0 For i = 1 To 生徒数 合計 = 合計 + 成績(i, 科目番号) Next Return 合計 End Function Public Function 生徒の合計点(ByVal 生徒番号 As Integer) As Double Dim i, 合計 As Integer 合計 = 0 For i = 1 To 科目数 合計 = 合計 + 成績(生徒番号, i) Next Return 合計 End Function