需要有关评分机制的帮助

时间:2014-04-03 11:39:44

标签: vb.net

所以我创建了一个简单的评分机制,程序比较两个列表框中的单词,并根据准确性分配点。

积分分配如下:

  • 2分正确答案(带字母的正确字词)
  • 1分为部分正确答案(右字没有大写字母)
  • 0分时不正确

如果单词匹配,则评分机制可以正常工作,但是当某人的类型与正确的单词完全不同时,如果它有大写字母,它仍会分配2分,如果没有大写字母,则分配1分。

我缺少一段代码,告诉程序如果单词与正确答案完全不匹配,则分配0分。

这是我的一段代码,你能告诉我需要添加什么吗?

Dim UserScore As Integer = 0 

For Counter As Integer = 0 To lstStudentAnswers.Items.Count - 1
    If UCase(lstStudentAnswers.Items(Counter).ToString) = UCase(lstProgramAnswers.Items(Counter).ToString) Then
        UserScore = UserScore + 1

        If Char.IsUpper(lstStudentAnswers.Items(Counter).ToString, 0) Then
            UserScore = UserScore + 1
        End If
    End If

    txtTotalScore.Text = UserScore
Next

2 个答案:

答案 0 :(得分:1)

我会做以下...(假设程序答案有正确的情况)。

Dim UserScore As Integer = 0 


For Counter As Integer = 0 To lstStudentAnswers.Items.Count - 1



    If UCase(lstStudentAnswers.Items(Counter).ToString) = UCase(lstProgramAnswers.Items(Counter).ToString) Then
        'User answer and Program answer are the same case insensitive.
        UserScore = UserScore + 1

        If lstStudentAnswers.Items(Counter).ToString = lstProgramAnswers.Items(Counter).ToString Then
            'Additional point for getting case right
            UserScore = UserScore + 1

        End If

    End If
    txtTotalScore.Text = UserScore

答案 1 :(得分:1)

这是一个比较两个单词的功能:

Private Function CompareWords(ByVal submittedWord As String, ByVal expectedWord As String) As Integer

    Dim result As Integer = 0

    If submittedWord.ToLower() <> expectedWord.ToLower() Then
        ' Submitted word is not the same as expected word
        Return result
    End If

    ' Words are the same, but need to check case of each character
    result += 1

    For letterIndex As Integer = 0 To submittedWord.Length - 1
        If submittedWord(letterIndex) <> expectedWord(letterIndex) Then
            ' Case of submitted word is not the same as the expected word
            Return result
        End If
    Next
    result += 1

    Return result

End Function

通过迭代学生答案,您只需提供学生答案和课程答案即可获得最终分数。