0

我正在尝试创建一个成绩计算器程序,但遇到了两个问题:

  1. 获得正确的输出(因为我得到了荒谬的数字)和
  2. 让我的柜台工作。

基本形式基本上是一进七级输入:

  • 3 次考试(分别占 15%、20% 和 20%)
  • 一个项目(权重10%),
  • 作业(权重 20%),
  • 同行评议(权重 5%),
  • 编程语言演示(权重 10%)

并且个人应该得到他们的数字等级、他们的字母等级和两个计数器的输出,这些计数器计算有多少人得到了A'sF's

例如,当我输入 3 个考试成绩时:82, 87, 91; Assignments: 94; Peer reviews: 100; programming language presentation: 90;final project: 92,

当它显然应该是和 numeric的字母等级时,我得到了最终的数字等级253.90和字母等级。FA89.90

我的计数器也无法正常工作,因为它们没有显示count,但我觉得我把它放在了正确的位置(显示输出)。我在这里到底做错了什么?这是我的代码

Option Strict On

Public Class frmGradeCalculator
    'declare Constants
    Const EXAM1GRADE_WEIGHT As Decimal = 0.15D
    Const EXAM2GRADE_WEIGHT As Decimal = 0.2D
    Const EXAM3GRADE_WEIGHT As Decimal = 0.2D
    Const HOMEWORKGRADE_WEIGHT As Decimal = 0.2D
    Const HOMEWORKPEERREVIEW_WEIGHT As Decimal = 0.05D
    Const LANGUAGEQUICKREFERENCE_WEIGHT As Decimal = 0.1D
    Const FINALPROJECT_WEIGHT As Decimal = 0.1D

    'Declare module variables
    Dim mdecFinalNumericGrade As Decimal
    Dim mstrFinalLetterGrade As String
    Dim mintStudentsWithAs As Integer
    Dim mintStudentsWithFs As Integer

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        'declare variables
        Dim decExam1Grade As Decimal
        Dim decExam2Grade As Decimal
        Dim decExam3Grade As Decimal
        Dim decHomeworkGrade As Decimal
        Dim decPeerReviewGrade As Decimal
        Dim decLanguageReferenceGrade As Decimal
        Dim decFinalProjectGrade As Decimal
        Dim decPercent As Decimal

        'check for blanks
        If (txtExam1Grade.Text) = "" Then
            MessageBox.Show("You Can't Leave Exam 1 Blank")
            Exit Sub
        End If

        'check for numeric
        If IsNumeric(txtExam1Grade.Text) = False Then 'value is not numeric
            MessageBox.Show("Please enter a numeric value for Exam 1!")
            Exit Sub
        End If

        'check for blanks
        If (txtExam2Grade.Text) = "" Then
            MessageBox.Show("Please enter Exam 2!")
            Exit Sub
        End If
        'check for everything else
        If IsNumeric(txtExam2Grade.Text) = False Then 'Value is not numeric
            MessageBox.Show("Please enter a numeric value for Exam 2!")
            Exit Sub
        End If

        'check for blanks
        If (txtExam3Grade.Text) = "" Then
            MessageBox.Show("Please enter Exam 3!")
            Exit Sub
        End If

        'check for numerics
        If IsNumeric(txtExam3Grade.Text) = False Then
            MessageBox.Show("Please enter a positive numeric value for Exam3!")
            Exit Sub
        End If

        'check for blanks
        If (txtHomeworkGrade.Text) = "" Then
            MessageBox.Show("Please enter Homework Grade!")
            Exit Sub
        End If

        'check for numerics
        If IsNumeric(txtHomeworkGrade.Text) = False Then
            MessageBox.Show("Please enter a numeric positive value for Homework Grade!")
            Exit Sub
        End If

        'check for blanks
        If (txtPeerReviewGrade.Text) = "" Then
            MessageBox.Show("Please enter a Peer Review Grade!")
            Exit Sub
        End If

        'check for numerics
        If IsNumeric(txtPeerReviewGrade.Text) = False Then
            MessageBox.Show("Please enter a numeric positive value for Peer Review Grade!")
            Exit Sub
        End If

        'check for blanks
        If (txtLanguageReferenceGrade.Text) = "" Then
            MessageBox.Show("Please enter a Language Reference Grade!")
            Exit Sub
        End If

        'check for numerics
        If IsNumeric(txtLanguageReferenceGrade.Text) = False Then
            MessageBox.Show("Please enter a numeric positive value for Language Reference Grade!")
            Exit Sub
        End If
        'check for blanks
        If (txtFinalProjectGrade.Text) = "" Then
            MessageBox.Show("Please enter a Final Project Grade!")
            Exit Sub
        End If

        'check for numerics
        If IsNumeric(txtFinalProjectGrade.Text) = False Then
            MessageBox.Show("Please enter a numeric positive value for Final Project Grade!")
            Exit Sub
        End If

        'convert data types
        decExam1Grade = Convert.ToDecimal(txtExam1Grade.Text)
        decExam2Grade = Convert.ToDecimal(txtExam2Grade.Text)
        decExam3Grade = Convert.ToDecimal(txtExam3Grade.Text)
        decHomeworkGrade = Convert.ToDecimal(txtHomeworkGrade.Text)
        decPeerReviewGrade = Convert.ToDecimal(txtPeerReviewGrade.Text)
        decLanguageReferenceGrade = Convert.ToDecimal(txtLanguageReferenceGrade.Text)
        decFinalProjectGrade = Convert.ToDecimal(txtFinalProjectGrade.Text)
        mdecFinalNumericGrade = (decExam1Grade * EXAM1GRADE_WEIGHT) + _
                                (decExam2Grade * EXAM2GRADE_WEIGHT) + _
                                (decExam3Grade * EXAM3GRADE_WEIGHT) + _
                                (decHomeworkGrade * HOMEWORKGRADE_WEIGHT) + _
                                (decPeerReviewGrade * HOMEWORKPEERREVIEW_WEIGHT) + _
                                (decLanguageReferenceGrade + LANGUAGEQUICKREFERENCE_WEIGHT) + _
                                (decFinalProjectGrade + FINALPROJECT_WEIGHT)

        'check for 0 or positive
        If decExam1Grade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Exam 1!")
            Exit Sub
        End If

        'check for 0 or positive
        If decExam2Grade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Exam 2!")
            Exit Sub
        End If

        'check for 0 or positive
        If decExam3Grade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Exam 3!")
            Exit Sub
        End If

        'check for 0 or positive
        If decHomeworkGrade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Homework Grade!")
            Exit Sub
        End If

        'check for 0 or positive
        If decPeerReviewGrade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Peer Review Grade!")
            Exit Sub
        End If

        'check for 0 or positive
        If decLanguageReferenceGrade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Language Reference!")
            Exit Sub
        End If

        'check for 0 or positive
        If decFinalProjectGrade < 0 Then
            MessageBox.Show("Please enter a positive value or zero for Final Project Grade!")
            Exit Sub
        End If

        'make sure values are less than 100
        If decExam1Grade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        If decExam2Grade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        If decExam3Grade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        If decHomeworkGrade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        If decPeerReviewGrade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        If decLanguageReferenceGrade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        If decFinalProjectGrade > 100 Then
            MessageBox.Show("Please enter a value thats 100 or less!")
        End If

        'Determine grade per letter
        Select Case decpercent
            Case Is >= 89.5D
                mstrFinalLetterGrade = "A"
                mintStudentsWithAs += 1
            Case Is >= 79.5D
                mstrFinalLetterGrade = "B"
            Case Is >= 69.5D
                mstrFinalLetterGrade = "C"
            Case Is >= 59.5D
                mstrFinalLetterGrade = "D"
            Case Else
                mstrFinalLetterGrade = "F"
                mintStudentsWithFs += 1
        End Select

        lblFinalLetterGrade.Text = mstrFinalLetterGrade

        'display outputs
        lblFinalNumericGrade.Text = mdecFinalNumericGrade.ToString("f2")
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'clear the texboxes and labels
        txtExam1Grade.Clear()
        txtExam2Grade.Clear()
        txtExam3Grade.Clear()
        txtHomeworkGrade.Clear()
        txtPeerReviewGrade.Clear()
        txtLanguageReferenceGrade.Clear()
        txtFinalProjectGrade.Clear()
        lblFinalLetterGrade.Text = ""
        lblFinalNumericGrade.Text = ""

        'setcursor back to top textbox
        txtExam1Grade.Focus()

    End Sub

    Private Sub btnReset_Click(ByVal sende As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

        'reset module level variables
        mdecFinalNumericGrade = 0
        mstrFinalLetterGrade = ""
        mintStudentsWithAs = 0
        mintStudentsWithFs = 0

    End Sub

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'close the form
        End
    End Sub

    Private Sub frmGradeCalculator_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
4

1 回答 1

1

您的最终总成绩是错误的,因为您没有将语言演示文稿和最终项目乘以它们的权重,而是将权重添加到分数中:

  • 考试 1 = 82 * .15 = 12.3
  • 考试 2 = 87 * .20 = 17.4
  • 考试 3 = 91 * .20 = 18.2
  • 作业 = 94 * .20 = 18.8
  • 同行评审 = 100 * .05 = 5
  • 语言表达 = 90 + .10 = 90.1
  • 最终项目 = 92 + .10 = 92.1

注意最后两个值的加法(而不是乘法)。总数为 253.9。

将 medcFinalNumericGrade 的最后两个计算更改为:

(decLanguageReferenceGrade * LANGUAGEQUICKREFERENCE_WEIGHT) + _
(decFinalProjectGrade * FINALPROJECT_WEIGHT)

您将始终得到“F”,因为decpercent从未分配过值,因此会执行 Else Case。分配 decpercent 一个值,或使用 mdecFinalNumericGrade。

例如:

Select Case mdecFinalNumericGrade

代替

Select Case decpercent

修复 Select Case 后,您的计数应该会起作用(除非您重置表单)。

于 2012-09-27T05:21:27.943 回答