1 Attachment(s)
Classification Estimator with a Function-Help
Average Mark Classification
>=70 1st
60 -69 2.1
50-59 2.2
40-59 3rd
<39 Unclassified
I want to write a program to estimate the degree of classification from an average mark. For example, an average mark of 55% shd give 2.2 classification.
I need to add a Function that shd take a single parameter value for the average mark, and return the calssification average.
Here are my design: I am new to this and need code solution to this please.
Re: Classification Estimator with a Function-Help
You can use a Select Case statement to find what range a mark falls in. Start by reading the appropriate documentation, which will tell you all you need to know.
Re: Classification Estimator with a Function-Help
vb Code:
Dim Result As String
Select Case Mark
Case Is >= 70
Result = "1st"
Case Is >= 60
Result = "2.1"
Case Is >= 50
Result = "2.2"
Case Is >= 40
Result = "3rd"
Case Else
Result = "Unclassified"
End Select
Kris
Re: Classification Estimator with a Function-Help
God forbid anyone should be allowed to do their own homework.
Re: Classification Estimator with a Function-Help
Hi Jmc,
Thanks for your response but how do i display the classifications on the textbox called txtClassify assuming i click on button Estimate and type in a particular mark into the textbox called txtAvgMark
Thanks.
Re: Classification Estimator with a Function-Help
here's my attempt. textbox1 is avg mark, textbox2 is classification:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim values As New List(Of Object())
values.Add(New Object() {70, -1, "1st"})
values.Add(New Object() {60, 69, "2.1"})
values.Add(New Object() {50, 59, "2.2"})
values.Add(New Object() {40, 59, "3rd"})
values.Add(New Object() {0, 39, "Unclassified"})
Dim avgMark As Decimal
If Decimal.TryParse(TextBox1.Text, avgMark) Then
TextBox2.Text = (From v In values _
Where avgMark >= CInt(v(0)) AndAlso avgMark <= If(CInt(v(1)) = -1, avgMark + 1, CInt(v(1))) _
Select CStr(v(2))).FirstOrDefault
End If
End Sub
End Class
to put that in a function with a single parameter:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim avgMark As Decimal
If Decimal.TryParse(TextBox1.Text, avgMark) Then
TextBox2.Text = getClassification(avgMark)
End If
End Sub
Private Function getClassification(ByVal avg As Decimal) As String
Dim values As New List(Of Object())
values.Add(New Object() {70, -1, "1st"})
values.Add(New Object() {60, 69, "2.1"})
values.Add(New Object() {50, 59, "2.2"})
values.Add(New Object() {40, 59, "3rd"})
values.Add(New Object() {0, 39, "Unclassified"})
Return (From v In values _
Where avg >= CInt(v(0)) AndAlso avg <= If(CInt(v(1)) = -1, avg + 1, CInt(v(1))) _
Select CStr(v(2))).FirstOrDefault
End Function
End Class