Anyone know how to code STANDARD DEVIATION?

I'm stuck on a homework project.

Here's my code.
________________________________________________________________________
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Btn As System.Windows.Forms.Button
Friend WithEvents LBx As System.Windows.Forms.ListBox
Private Sub InitializeComponent()
Me.Btn = New System.Windows.Forms.Button()
Me.LBx = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
'Btn
'
Me.Btn.Location = New System.Drawing.Point(16, 8)
Me.Btn.Name = "Btn"
Me.Btn.Size = New System.Drawing.Size(264, 24)
Me.Btn.TabIndex = 0
Me.Btn.Text = "Analyze Grades"
'
'LBx
'
Me.LBx.Location = New System.Drawing.Point(16, 40)
Me.LBx.Name = "LBx"
Me.LBx.Size = New System.Drawing.Size(272, 329)
Me.LBx.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(304, 388)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.LBx, Me.Btn})
Me.Name = "Form1"
Me.Text = "Curving Grades"
Me.ResumeLayout(False)

End Sub

#End Region

________________________________________________________________________

Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn.Click
Dim i, a, b, c, d, f As Integer
Dim m, sd, sx, s As Integer
Dim scores() As Integer = {0, 59, 60, 65, 75, 56, 90, 66, 62, 98, 72, 95, 71, 63, 77, 65, 77, 65, 50, 85, 62}
Dim grade, first As String
Dim fmtstr As String = "{0,-5}, {1,20}"
Dim mean, score As String
first = "There were 20 exams"
LBx.Items.Clear()
LBx.Items.Add(first)
fmtstr = "{0,5}, {1,24}"
LBx.Items.Add(String.Format(fmtstr, "Mean:", (sum(scores) / 20)))
fmtstr = "{0,5}, {1,20}"
LBx.Items.Add(String.Format(fmtstr, "Std. Deviation:", (stdev(scores) / 7891.8)))
Math.Round(13.06, 2)
LBx.Items.Add(String.Format(fmtstr, "Score", "Grade"))


For i = 1 To 20
If scores(i) >= (m + (1.5 * sx)) Then grade = "A" Else
If (m - (0.5 * sx)) <= scores(i) And scores(i) < (m + (0.5 * sx)) Then grade = "C" Else
If (m - (1.5 * sx)) <= scores(i) And scores(i) < (m - (0.5 * sx)) Then grade = "D" Else
If scores(i) < m - (1.5 * sx) Then grade = "F"
LBx.Items.Add(String.Format(fmtstr, scores(i), grade))
grade = ""
Next i
End Sub


Function sum(ByVal s() As Integer) As Integer
'Set up mean calculation
Dim i, m As Integer
m = 0
For i = 1 To s.GetUpperBound(0)
m += s(i)
Next
Return m
End Function

Function stdev(ByVal s() As Integer) As Double
'Set up standard deviation
Dim i, m As Integer
Dim sx As Double
sx = 0
For i = 1 To s.GetUpperBound(0)
sx += ((s(i) - m) ^ 2)
Next
Return sx
End Function
End Class



______________________________________________________________________

If anyone could help me, I would deeply appreciate it!!!

Comments

  • : I'm stuck on a homework project.
    :
    : Here's my code.
    : ________________________________________________________________________
    : Public Class Form1
    : Inherits System.Windows.Forms.Form
    :
    : #Region " Windows Form Designer generated code "
    :
    : Public Sub New()
    : MyBase.New()
    :
    : 'This call is required by the Windows Form Designer.
    : InitializeComponent()
    :
    : 'Add any initialization after the InitializeComponent() call
    :
    : End Sub
    :
    : 'Form overrides dispose to clean up the component list.
    : Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    : If disposing Then
    : If Not (components Is Nothing) Then
    : components.Dispose()
    : End If
    : End If
    : MyBase.Dispose(disposing)
    : End Sub
    :
    : 'Required by the Windows Form Designer
    : Private components As System.ComponentModel.IContainer
    :
    : 'NOTE: The following procedure is required by the Windows Form Designer
    : 'It can be modified using the Windows Form Designer.
    : 'Do not modify it using the code editor.
    : Friend WithEvents Btn As System.Windows.Forms.Button
    : Friend WithEvents LBx As System.Windows.Forms.ListBox
    : Private Sub InitializeComponent()
    : Me.Btn = New System.Windows.Forms.Button()
    : Me.LBx = New System.Windows.Forms.ListBox()
    : Me.SuspendLayout()
    : '
    : 'Btn
    : '
    : Me.Btn.Location = New System.Drawing.Point(16, 8)
    : Me.Btn.Name = "Btn"
    : Me.Btn.Size = New System.Drawing.Size(264, 24)
    : Me.Btn.TabIndex = 0
    : Me.Btn.Text = "Analyze Grades"
    : '
    : 'LBx
    : '
    : Me.LBx.Location = New System.Drawing.Point(16, 40)
    : Me.LBx.Name = "LBx"
    : Me.LBx.Size = New System.Drawing.Size(272, 329)
    : Me.LBx.TabIndex = 1
    : '
    : 'Form1
    : '
    : Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    : Me.ClientSize = New System.Drawing.Size(304, 388)
    : Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.LBx, Me.Btn})
    : Me.Name = "Form1"
    : Me.Text = "Curving Grades"
    : Me.ResumeLayout(False)
    :
    : End Sub
    :
    : #End Region
    :
    : ________________________________________________________________________
    :
    : Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn.Click
    : Dim i, a, b, c, d, f As Integer
    : Dim m, sd, sx, s As Integer
    : Dim scores() As Integer = {0, 59, 60, 65, 75, 56, 90, 66, 62, 98, 72, 95, 71, 63, 77, 65, 77, 65, 50, 85, 62}
    : Dim grade, first As String
    : Dim fmtstr As String = "{0,-5}, {1,20}"
    : Dim mean, score As String
    : first = "There were 20 exams"
    : LBx.Items.Clear()
    : LBx.Items.Add(first)
    : fmtstr = "{0,5}, {1,24}"
    : LBx.Items.Add(String.Format(fmtstr, "Mean:", (sum(scores) / 20)))
    : fmtstr = "{0,5}, {1,20}"
    : LBx.Items.Add(String.Format(fmtstr, "Std. Deviation:", (stdev(scores) / 7891.8)))
    : Math.Round(13.06, 2)
    : LBx.Items.Add(String.Format(fmtstr, "Score", "Grade"))
    :
    :
    : For i = 1 To 20
    : If scores(i) >= (m + (1.5 * sx)) Then grade = "A" Else
    : If (m - (0.5 * sx)) <= scores(i) And scores(i) < (m + (0.5 * sx)) Then grade = "C" Else
    : If (m - (1.5 * sx)) <= scores(i) And scores(i) < (m - (0.5 * sx)) Then grade = "D" Else
    : If scores(i) < m - (1.5 * sx) Then grade = "F"
    : LBx.Items.Add(String.Format(fmtstr, scores(i), grade))
    : grade = ""
    : Next i
    : End Sub
    :
    :
    : Function sum(ByVal s() As Integer) As Integer
    : 'Set up mean calculation
    : Dim i, m As Integer
    : m = 0
    : For i = 1 To s.GetUpperBound(0)
    : m += s(i)
    : Next
    : Return m
    : End Function
    :
    : Function stdev(ByVal s() As Integer) As Double
    : 'Set up standard deviation
    : Dim i, m As Integer
    : Dim sx As Double
    : sx = 0
    : For i = 1 To s.GetUpperBound(0)
    : sx += ((s(i) - m) ^ 2)
    : Next
    : Return sx
    : End Function
    : End Class
    :
    :
    :
    : ______________________________________________________________________
    :
    : If anyone could help me, I would deeply appreciate it!!!
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion