English 中文(简体)
合并增加2个阵列数据?
原标题:adding 2d array column data together?

if you could possibly point me to the right direction, that would be great. i have tried researching about this but found no solution.

i 设有2个阵列,拥有学生名称和3年级(学生、数学、科学)。

student array (24,3)

Now, i would like to use the data which is held within the array to create averages.

I need a total class average for: maths column, eng column, and science. I also need an overall average for all subjects.

法典一迄今为止已经取得了一些奇迹。

studentarray(i,1) / count 
studentarray(i,2) / count

studentarray(i,3) / count

totalaverage = (studentarray(i,1) + studentarray(i,2) + studentarray(i,3)) / count

头3个平均数只给我带来阵列中第一个条目的结果。 然后,计算将仅显示在3栏(即101010)内显示的数据。

any!

问题回答
Function CalcSubjectAverage(ByVal studentArray(,) As Integer, ByVal subject As Integer) As Single
    Dim total As Single
    For i As Integer = 0 To studentArray.Length
        total += studentArray(i, 0)
    Next

    Return total / studentArray.Length
End Function

你们首先需要增加科目,然后可以计算平均数字:

我希望这也有助于:

我在守则中提出了必要的意见。

Code: this are 2D dynamic arrays StudentArray(,) for storage of data of student grades Ave_Values_per_Subject(,) for storing average values Ave_Values_per_Student() actually you can use only the first array, but to make the codes more understandable, _ we declare another 2 arrays Dim StudentArray(,), Ave_Values_per_Subject(,), Ave_Values_per_Student() As Object this is the function Sub SolveMyProblem(ByVal Num_of_Students As UInteger, ByVal Num_of_Subjects As UInteger)

      get the number of students and resize the array
    ReDim StudentArray(Num_of_Students - 1, Num_of_Subjects - 1), Ave_Values_per_Subject(0, Num_of_Subjects - 1), _
          Ave_Values_per_Student(Num_of_Students - 1)
      you can imagine this as having a table with Num_of_Students as the number of rows and Num_of_Subjects as the _
      number of columns
      StudentArray(0,0) gives the value of student #1 at subject #1 (say english) _
      StudentArray(0,1) gives the value of student #1 at subject #2 (say math) _
      StudentArray(1,3) gives the value of student #2 at subject #3 (say science) and so on

      example: we have 4 students with english, math, and science as subjects
      thus Num_of_Students = 4 and Num_of_Subjects = 3 giving us StudentArray(3,2) and Ave_Values_per_Subject(0,2)
      Suppose the grades of student #1 for english, math, and science are 70, 80, and 90 respectively; _
      student #2 = {75, 80, 90}; student #3 = {75, 85, 95}; and student #4 = {60, 100, 85}
      Suppose index 0 of StudentArray (StudentArray(0,0)) represents english subject; _
      StudentArray (0,1) = math; and StudentArray (0,2) = science

       to calculate for the average of students for EACH subject and to store it in a separate array:
    For subjectCount = 0 To UBound(StudentArray, 2)
        Dim SumPerSubject As Single
        For studentCount = 0 To UBound(StudentArray, 1)
            SumPerSubject += StudentArray(studentCount, subjectCount)
        Next
          average of students per subject:
        Ave_Values_per_Subject(0, subjectCount) = SumPerSubject / (UBound(StudentArray, 1) + 1)
          the average of students per subject is determined and stored in the above array
          this means that the average of values for english is stored in Ave_Values_per_Subject(0,0) _
          Ave_Values_per_Subject(0,1) for math; and Ave_Values_per_Subject(0,2) for science
    Next

       to calculate for the average of EACH student on all subjects:
    For studentCount = 0 To UBound(StudentArray, 1)
        Dim SumPerStudent As Single
        For subjectCount = 0 To UBound(StudentArray, 2)
            SumPerStudent += StudentArray(studentCount, subjectCount)
        Next
          ave values of each student on all subjects:
        Ave_Values_per_Student(studentCount) = SumPerStudent / 3
    Next
End Sub




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签