📄 form1.vb
字号:
Imports system.math
Public Class Form1
Structure arrayd
Dim value As Single
Dim count As Integer
End Structure
Dim Data() As Single = {22, 45, 65, 85, 25, 74, 50, 60, 58, 49, 39, 65, 47, 15, 60, 75, 60, 52, 35, 45, 48, 55, 66, 67, 48, 25, 33, 51, 60, 59}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
depa(Data)
TextBox1.Text = mAVG(Data)
TextBox2.Text = Med(Data)
TextBox3.Text = Normal(Data)
TextBox4.Text = minu(Data)
textbox6.text = depas(Data)
TextBox7.Text = std(Data)
TextBox8.Text = stdq(Data)
TextBox9.Text = stdev(Data)
stdch(Data)
End Sub
Public Function sort(ByRef vData() As Single) As Single
Dim i As Integer
Dim j As Integer
Dim arrTemp As Single
For i = 0 To UBound(vData)
For j = i + 1 To UBound(vData)
If vData(i) > vData(j) Then
arrTemp = vData(i)
vData(i) = vData(j)
vData(j) = arrTemp
End If
Next
Next
End Function
Public Function mAVG(ByRef vData() As Single) As Single
Dim i As Integer
Dim l As Integer
Dim s As Single
l = UBound(vData)
For i = 0 To UBound(vData)
s = s + vData(i)
Next
mAVG = s / (l + 1)
End Function
Public Function Med(ByRef vData() As Single) As Single
Dim l As Integer
sort(vData)
l = UBound(vData)
If (l Mod 2) = 0 Then
Med = vData(l / 2)
Else
Med = (vData((l - 1) / 2) + vData((l + 1) / 2)) / 2
End If
End Function
Public Function Normal(ByRef vData() As Single) As Single
Dim i As Integer
Dim j As Integer
Dim tag As Integer = 0
Dim arrmax As Single
Dim arry(UBound(vData)) As arrayd
arrmax = 0
sort(vData)
For i = 0 To UBound(vData)
With arry(i)
.value = vData(i)
End With
Next
For i = 0 To UBound(vData)
For j = tag To UBound(vData)
If arry(i).value = arry(j).value Then
arry(i).count = arry(i).count + 1
Else
tag = j
Exit For
End If
Next
Next
For i = 0 To UBound(arry)
If arry(i).count > arrmax Then
arrmax = arry(i).count
tag = i
End If
Next
Return arry(tag).value
End Function
Public Function minu(ByRef vData() As Single) As Single
Dim maxn As Single
Dim minn As Single
sort(vData)
minn = vData(0)
maxn = vData(UBound(vData))
minu = maxn - minn
End Function
Public Function depa(ByRef vData() As Single) As Single
Dim i As Integer
For i = 0 To UBound(vData)
TextBox5.AppendText((Str(vData(i) - mAVG(vData))) & " ")
Next
End Function
Public Function depas(ByRef vData() As Single) As Single
Dim i As Integer
Static sum As Single = 0
For i = 0 To UBound(vData)
sum = sum + ((vData(i) - mAVG(vData)) ^ 2)
Next
depas = sum
End Function
Public Function std(ByRef vData() As Single) As Single
std = sqrt(stdq(vData))
End Function
Public Function stdq(ByRef vData() As Single) As Single
Dim i As Integer
Dim sum As Single = 0
For i = 0 To UBound(vData)
sum = sum + ((vData(i) - mAVG(vData)) ^ 2)
Next
stdq = sum / (UBound(vData) + 1)
End Function
Public Function stdev(ByRef vData() As Single) As Single
Dim i As Integer
Dim sum As Single = 0
For i = 0 To UBound(vData)
sum = sum + ((vData(i) - mAVG(vData)) ^ 2)
Next
stdev = sqrt(sum / (UBound(vData)))
End Function
Public Function stdch(ByRef vData() As Single) As Single
Dim i As Single
i = stdev(vData)
TextBox10.Text = Str(i / mAVG(vData) * 100) & "%"
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -