ASSIGNMENT 教师有六名学生,并希望您创建一个应用程序,将其成绩数据存储在一个文件中并打印成绩报告。应用程序应具有存储以下学生数据的结构:名称(字符串),测试分数(五个双打的数组)和平均值(双精度)。因为教师有六个学生,所以应用程序应使用六个结构变量的数组。 应用程序应允许用户输入每个学生的数据,并计算平均测试分数。 用户应该能够将数据保存到文件中,从文件中读取数据,并打印显示每个学生的测试分数和平均分数的报告。表格显示了一个meny系统。如果您愿意,可以选择按钮。 输入验证:不要接受小于零或大于100的测试分数。
我对它应该如何构建的理解
对于片刻我不明白,在FOR EACH循环中,我无法累积它说我不允许使用+。我试图从txtScore1Std1获得分数(例如)将其分配给dblTestScoreArray并使用每个循环来查找这5个分数的总和,当找到平均值并将其输出到lbl平均值为1号学生。
代码模块:
Module StudentTestScoresModule
Const intMAX_SUBSCRIPT_STUDENT As Integer = 6
Const intMAX_SUBSCRIPT_STUDENT_SCORES As Integer = 5
'create structure
Public Structure StudentData
Dim strName As String
Dim dblTestScoresArray() As Double
Dim dblAverage As Double
End Structure
Dim dblTotalStd1 As Double
Dim dblScore As Double
Dim StudentsArray(intMAX_SUBSCRIPT_STUDENT) As StudentData
Sub StudentNameDataInput()
StudentsArray(0).strName = MainForm.txtStdName1.Text
StudentsArray(1).strName = MainForm.txtStdName2.Text
StudentsArray(2).strName = MainForm.txtStdName3.Text
StudentsArray(3).strName = MainForm.txtStdName4.Text
StudentsArray(4).strName = MainForm.txtStdName5.Text
StudentsArray(5).strName = MainForm.txtStdName6.Text
End Sub
Sub StudentScoreDataInput()
For intIndex = 0 To intMAX_SUBSCRIPT_STUDENT
ReDim StudentsArray(intIndex).dblTestScoresArray(4)
Next
'test scores for first student
StudentsArray(0).dblTestScoresArray(0) = CDbl(MainForm.txtScore1Std1.Text)
StudentsArray(1).dblTestScoresArray(1) = CDbl(MainForm.txtScore2Std1.Text)
StudentsArray(2).dblTestScoresArray(2) = CDbl(MainForm.txtScore3Std1.Text)
StudentsArray(3).dblTestScoresArray(3) = CDbl(MainForm.txtScore4Std1.Text)
StudentsArray(4).dblTestScoresArray(4) = CDbl(MainForm.txtScore5Std1.Text)
For Each i As StudentData In StudentsArray
dblTotalStd1 += i
Next
dblAverage = dblTotalStd1 / intMAX_SUBSCRIPT_STUDENT_SCORES
MainForm.lblAvgStd1.Text = (dblAverage.ToString)
End Sub
Sub CalculateAverage()
End Sub
End Module
代码主要表格:
Public Class MainForm
Private Sub mnuHelpAbout_Click(sender As Object, e As EventArgs) Handles mnuHelpAbout.Click
'about program
MessageBox.Show("Student test score calculator version 0.1")
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
' Close(program)
Me.Close()
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
StudentScoreDataInput()
End Sub
End Class
答案 0 :(得分:1)
只是通过观察而不进行测试,你需要做的是什么;
'untested code
For Each i As StudentData In StudentsArray
For Each S as Double in i.dblTestScoresArray
dblTotalStd1 += s
Next
Next
你不能在结构上做+ =,你需要在成员上做,因为它是一个数组,你需要循环它