PG. 218 1. Grade Point Average Write a program to calculate a student\'s GPA. Se
ID: 671596 • Letter: P
Question
PG. 218 1. Grade Point Average Write a program to calculate a student's GPA. See Figure 5.38 in "An Introduction to Programming Using Visual Basic 2012". The user should enter the grade (A,B,C,D, or F) and the number of credit hours for a course, and then click on the Record This Course button. The user should then repeat this process for all his or her courses. After all the courses have been recorded, the user should click on the Calculate GPA button. A Function procedure should be used to calculate the quality points for a course.
Explanation / Answer
VB code for the same:
Public Class GPA_Form
Private Sub exitButton_Click(sender As System.Object, e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub entdatButton_Click(sender As System.Object, e As System.EventArgs) Handles entdatButton.Click
Const Prompt As String = "Enter number of Credit Hours:"
Const Title As String = "Credit Hours"
Const Prompt2 As String = "Enter grades:"
Const Title2 As String = "Grades"
Dim Credit As String
Dim Grades As String
Dim creditHrs As Integer
Dim grades As Char
Dim gradesCounter As Integer
Dim creditHrsAccumulator As Integer
Dim point As Integer
Dim gpaTot As Integer
Dim sumtot As Integer
Credit = InputBox(Prompt, Title)
Grades = InputBox(Prompt2, Title2)
Do While Credit <> String.Empty
Integer.TryParse(Credit, creditHrs)
Char.TryParse(Grades, grades)
gradesCounter += 1
creditHrsAccumulator += creditHrs
Select Case grades
Case "A"
point = 4
Case "B"
point = 3
Case "C"
point = 2
Case "D"
point = 1
Case "F"
point = 0
End Select
sumtot += point
gpaTot = sumtot / gradesCounter
tchData.Text = creditHrsAccumulator.ToString("N0")
numGrEnt.Text = gradesCounter.ToString("N0")
gpaData.Text = gpaTot.ToString("N2")
Credit = InputBox(Prompt, Title)
Grades = InputBox(Prompt2, Title2)
Loop
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.