系统如何识别问题是不是已被回答

Posted

技术标签:

【中文标题】系统如何识别问题是不是已被回答【英文标题】:how the system recognize if the question is already answered系统如何识别问题是否已被回答 【发布时间】:2019-04-03 01:53:08 【问题描述】:

如果用户想返回上一个问题,我想知道系统如何识别问题是否已经回答。如果它已经回答,答案将更新分数是否增加,或者如果答案未编辑,它将是相同的。

BUTTON1 是返回上一个问题 Button2 用于检查答案的真假 按钮 3 用于继续考试

这是我的代码 sn-ps:

Imports mysql.Data.MySqlClient
Imports System.Drawing
Imports System.IO

Public Class Exam
    'declaring variables for connection'
    Dim score As Integer
    Dim rightans As String
    Dim correct As Integer = 0
    Dim choice As String
    Dim choice1 As String
    Dim choice2 As String
    Dim choice3 As String
    Dim con As MySqlConnection
    Dim con1 As MySqlConnection
    Dim COMMAND As MySqlCommand
    Dim read As MySqlDataReader
    Dim da As MySqlDataAdapter
    Dim sql As String
    Private Sub Exam_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'setting the radiobutton to false, so that when the form load there is no shaded button'
        Label2.Text = 1
        A.Checked = False
        B.Checked = False
        C.Checked = False
        D.Checked = False
        con = New MySqlConnection

        Button1.Enabled = False
        con.ConnectionString = "server=localhost;userid=root;password=;database=user;"
        'calling sub
        qno()



    End Sub


Sub clear()
        'to set the radiobutton false/no shaded.
        A.Checked = False
        B.Checked = False
        C.Checked = False
        D.Checked = False
    End Sub

    Sub qno()
        'calling connection'
        Try
            con = New MySqlConnection
            con.ConnectionString = "server=localhost; user id=root; password=; database=user;"
            con.Open()
            sql = "SELECT * FROM user.math WHERE question_id = @ID;"
            COMMAND = New MySqlCommand
            With COMMAND
                .Connection = con
                .CommandText = sql
                .Parameters.Clear()
                .Parameters.AddWithValue("@ID", Label2.Text)
                .ExecuteNonQuery()
            End With
            Dim arrImage() As Byte
            Dim dt As New DataTable
            da = New MySqlDataAdapter
            da.SelectCommand = COMMAND
            da.Fill(dt)
            If dt.Rows.Count > 0 Then

                arrImage = dt.Rows(0).Item(7)

                Dim mstream As New System.IO.MemoryStream(arrImage)

                Pic1.Image = Image.FromStream(mstream)
                question.Text = dt.Rows(0).Item(1)
                A.Text = dt.Rows(0).Item(2)
                B.Text = dt.Rows(0).Item(3)
                C.Text = dt.Rows(0).Item(4)
                D.Text = dt.Rows(0).Item(5)

            Else
                MsgBox("No results!")
            End If
        Catch ex As MySqlException
            MsgBox(ex.Message)
        Finally
            con.Close()
            da.Dispose()
        End Try

    End Sub

    Sub increment()
        'incrementing the score f the answer is correct'
        Dim i As Integer = 0
        i = Label2.Text
        i = i + 1
        Label2.Text = i
        If Label2.Text > 1 Then
            Button1.Enabled = True
        End If

    End Sub

    Sub decrement()
        'incrementing the score f the answer is correct'
        Dim i As Integer = 1
        i = Label2.Text
        i = i - 1
        Label2.Text = i
        If Label2.Text = 1 Then
            Button1.Enabled = False
        End If

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'checking of the user answer the questions'
        If ((A.Checked = False) And (B.Checked = False) And (C.Checked = False) And (D.Checked = False)) Then
            MsgBox("Please answer the question")

        Else
            'if the examinee answers all the examination it will call another questions from database'
            If A.Checked = True Then
                con.Open()
                ' Dim ans As String
                Dim arren As String = "A"
                Dim sql As String = ("select answer from user.math where question_id = '" & Label2.Text & "' ")
                COMMAND = New MySqlCommand(sql, con)
                Dim it As String

                read = COMMAND.ExecuteReader
                If read.HasRows Then
                    If read.Read Then
                        it = read.Item("answer")
                        If it = choice Then
                            correct = correct + 1
                            Label4.Text = correct
                        ElseIf it <> choice And Label2.Text <= 1 Then
                            correct = correct - 1
                            Label4.Text = correct
                        End If

                    End If

                    clear()


                End If


                If Label2.Text = 10 Then
                    MessageBox.Show("proceed to other subject test")
                End If
                con.Close()




    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        decrement()
        qno()
    End Sub
End Class

【问题讨论】:

那里的代码太多了,你的问题也太模糊了。您需要对问题非常具体,并且只发布与该问题相关的代码。如果您基本上是在说“这就是我所做的,其余的我该怎么做”,那么这不是我们真正要回答的。无论你想做什么,你都需要先尝试去做,然后你可以问为什么它不起作用。然后,您将只发布与该问题相关的代码。 开启 Option Strict。这将帮助您避免运行时错误。 如果您将按钮命名为有意义的名称,将会很有帮助。 Button2 看起来像 Accept Answer 但 Button1 和 Button3 没有多大意义。 您正在检查 Button2 中检查了哪些单选按钮,那么为什么所有这些检查更改的事件? 去掉 Sub qno 中的.ExecuteNonQuery()。选择语句是返回行的查询,您可以使用 da.Fill(dt) 执行命令 【参考方案1】:

未经测试,因为我没有您的数据库。上面的评论和内联。

Public Class Form3

    Dim correct As Integer = 0

    Private Sub Exam_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'setting the radiobutton to false, so that when the form load there is no shaded button'
        Label2.Text = "1"
        A.Checked = False
        B.Checked = False
        C.Checked = False
        D.Checked = False
        Button1.Enabled = False
        qno()
    End Sub
    Private Sub clear()
        'to set the radiobutton false/no shaded.
        A.Checked = False
        B.Checked = False
        C.Checked = False
        D.Checked = False
    End Sub

    Private Sub qno()
        Try
            'Using...End Using blocks will close and dispose of your objects
            Using con = New MySqlConnection("server=localhost;userid=root;password=;database=user;")
                Using Cmd = New MySqlCommand("SELECT * FROM user.math WHERE question_id = @ID;", con)
                    Cmd.Parameters.AddWithValue("@ID", Label2.Text)
                    Dim arrImage() As Byte
                    Dim dt As New DataTable
                    Using da = New MySqlDataAdapter
                        da.SelectCommand = Cmd
                        da.Fill(dt)
                        If dt.Rows.Count > 0 Then
                            'Not at all sure about this picture code
                            arrImage = CType(dt.Rows(0).Item(7), Byte())
                            Dim mstream As New System.IO.MemoryStream(arrImage)
                            Pic1.Image = Image.FromStream(mstream)
                            question.Text = dt.Rows(0).Item(1).ToString
                            A.Text = dt.Rows(0).Item(2).ToString
                            B.Text = dt.Rows(0).Item(3).ToString
                            C.Text = dt.Rows(0).Item(4).ToString
                            D.Text = dt.Rows(0).Item(5).ToString
                            'guessing that answer it item 6
                            HiddenLabel.Text = dt.Rows(0).Item(6).ToString
                        Else
                            MsgBox("No results!")
                        End If
                    End Using
                End Using
            End Using
        Catch ex As MySqlException
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'checking of the user answer the questions'
        If ((A.Checked = False) And (B.Checked = False) And (C.Checked = False) And (D.Checked = False)) Then
            MsgBox("Please answer the question")
            Exit Sub
        End If
        'The correct answer was put in the HiddenLabel.Text (Visible set to False)
        'in the qno Sub
        Dim CorrectAnswer As String = HiddenLabel.Text
        Dim UserChoice As String = ""

        If A.Checked Then
            UserChoice = "A"
        ElseIf B.Checked Then
            UserChoice = "B"
        ElseIf C.Checked Then
            UserChoice = "C"
        Else
            UserChoice = "D"
        End If

        If UserChoice = CorrectAnswer Then
            correct += 1
        Else
            'It is very hard to get a good score if it is decremented with every wrong answer
            'Why not skip this and just give a zero for a wrong answer
            correct -= 1
        End If
        Label4.Text = correct.ToString
        clear()
        If Label2.Text = "10" Then
            MessageBox.Show("proceed to other subject test")
            Me.Hide()
            exam2.Show()
        Else
            'Add code to keep track of question number in 
            'Add code to show the next question
        End If

    End Sub

【讨论】:

如果用户想回到其他问题并编辑它怎么办?如果分数要减少或仍然相同,系统如何? 如果您允许用户返回并更改他的答案,他将继续返回,直到他看到他的分数上升。 如果我不想显示分数并自动保存到数据库怎么办? 如果您想允许用户返回,您必须保存每个问题的答案,然后显示上一个问题的答案。由于您在进行过程中得分,因此您需要通过再次检查它是对还是错,如果错误则增加,如果正确则减少,来反转前一个问题的分数。添加此功能确实使您的代码复杂化。

以上是关于系统如何识别问题是不是已被回答的主要内容,如果未能解决你的问题,请参考以下文章

opencv人脸识别用哪种方法比较好?Eigenfaces?Fisherfaces?LBP?

对话系统 常用术语

iOS 上的全系统手势识别

《PHP程序员面试笔试宝典》——如何巧妙地回答面试官的问题?

DTD 是不是已弃用?

程序员面试问题-如何回答有坑问题