Develop a single Windows Form application to calculate and display the mean, var
ID: 3665880 • Letter: D
Question
Develop a single Windows Form application to calculate and display the mean, variance, and standard deviation of a minimum of 6 data points. Based on the mean, assign and display a letter grade based on the information shown below:
Mean:
Variance: =
Standard Deviation:
Grade:
Mean Range
Letter Grade
94+
A
88 – 93
B+
82 – 87
B
76 – 81
C+
70 – 75
C
64 – 69
D
63 -
F
General Requirements
The Windows Form should be easy to understand using appropriate labels and ToolTip controls to help the user navigate through the application
Comments should be placed throughout your VB code. Variables and control objects should follow common naming conventions
Data entered into control objects should be stored in an Array using an appropriate data type
Display the output using a textbox or label control object
Use Error Handling (Try...Catch…Finally) to account for common errors
Display a message to the user where necessary
Can someone tell me whats wrong with this code ?
private double getStandardDeviation(List<double> doubleList)
{
double average = doubleList.Average();
double sumOfDerivation = 0;
foreach (double value in doubleList)
{
sumOfDerivation += (value) * (value);
}
double sumOfDerivationAverage = sumOfDerivation / (doubleList.Count - 1);
return Math.Sqrt(sumOfDerivationAverage - (average*average));
}
Public Class frmMain
Private Function CalculateGrade _
(ByVal testScore1 As Decimal, ByVal testScore2 As Decimal, _
ByVal testScore3 As Decimal) As String
Dim AverageScore As String
Dim strLetterGrade As String
Dim intNum1 As Integer
Dim intNum2 As Integer
Dim intNum3 As Integer
Dim intNum4 As Integer
AverageScore = testScore1 + testScore2 + testScore3 / 3
strLetterGrade = {"A", "B","C", "D", "F"}
intNum1 = 90
intNum2 = 80
intNum3 = 70
intNum4 = 60
If AverageScore >= 90 Then
Return strLetterGrade("A")
Else
If AverageScore >= 80 Then
Return strLetterGrade("B")
Else
If AverageScore >= 70 Then
Return strLetterGrade("C")
Else
If AverageScore >= 60 Then
Return strLetterGrade("D")
Else
If AverageScore < 60 Then
Return strLetterGrade("F")
End If
End If
End If
End If
End If
Return strLetterGrade
End Function
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtTest1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTest1.KeyPress
' allows the text box to accept only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtTest2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTest2.KeyPress
' allows the text box to accept only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtTest3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTest3.KeyPress
' allows the text box to accept only numbers, the period, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtTest1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest1.TextChanged
lblGrade.Text = String.Empty
End Sub
Private Sub txtTest2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest2.TextChanged
lblGrade.Text = String.Empty
End Sub
Private Sub txtTest3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest3.TextChanged
lblGrade.Text = String.Empty
End Sub
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
End Sub
End Class
Mean Range
Letter Grade
94+
A
88 – 93
B+
82 – 87
B
76 – 81
C+
70 – 75
C
64 – 69
D
63 -
F
Explanation / Answer
problem is with your standard deviation calculation:
-----------------------------------------------------
To find standard deviation, here is the steps..
First we have to find average of all numbers and then find the variance.
To find the variance.. square of (each number - average)
Then square root of variance will give our required standard deviation.
So corrected standard deviatoin function:
--------------------------------------------
private double getStandardDeviation(List<double> doubleList)
{
//getting average
double average = doubleList.Average();
double sumOfDerivation = 0;
//calculating variance
foreach (double value in doubleList)
{
sumOfDerivation = sumOfDerivation + ((value-average) * (value-average));
}
//returning standard deviation
return Math.Sqrt(sumOfDerivation);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.