Write a program that uses an array of string objects to hold the five student names, an array of one character to hold the five students’ letter grades, and five arrays of doubles to hold each student’s set of test scores and average score. The program should allow the user to enter each student’s name and his or her four test scores. The program should store each student’s information in the arrays [20 points]. It should then calculate and display each student’s average test score [20 points] and a letter grade based on the average [20 points]. Input Validation: Do not accept test scores less than 0 or greater than 100 [10 points]
Module Module1
Sub Main()
Dim studentNames(4) As String
Dim letters(4) As Char
Dim scores1(3) As Double
Dim scores2(3) As Double
Dim scores3(3) As Double
Dim scores4(3) As Double
Dim scores5(3) As Double
Dim averages(4) As Double
getNameAndScores(1, scores1)
getNameAndScores(2, scores2)
getNameAndScores(3, scores3)
getNameAndScores(4, scores4)
getNameAndScores(5, scores5)
averages(0) = getAverageTestScore(scores1)
averages(1) = getAverageTestScore(scores2)
averages(2) = getAverageTestScore(scores3)
averages(3) = getAverageTestScore(scores4)
averages(4) = getAverageTestScore(scores5)
For i As Integer = 0 To 4
letters(i) = getLetter(averages(i))
Next
Console.WriteLine()
For i As Integer = 0 To 4
Console.WriteLine("The student name: " + studentNames(i))
Console.WriteLine("The average test score: " + averages(i).ToString())
Console.WriteLine("The letter grade: " + letters(i).ToString())
Console.WriteLine()
Next
Console.ReadLine()
End Sub
''' <summary>
''' gets name and scores
''' </summary>
''' <param name="student"></param>
''' <param name="testScores"></param>
''' <returns></returns>
''' <remarks></remarks>
Function getNameAndScores(ByRef student As Integer, ByRef testScores() As Double)
Console.Write("Enter the student name " + student.ToString() + ": ")
Dim name = Console.ReadLine()
For i As Integer = 0 To 3
testScores(i) = -1
While testScores(i) < 0 Or testScores(i) > 100
Console.Write("Enter the test score " + (i + 1).ToString() + ": ")
testScores(i) = Double.Parse(Console.ReadLine())
End While
Next
Return name
End Function
''' <summary>
''' gets average test score
''' </summary>
''' <param name="scores"></param>
''' <returns></returns>
''' <remarks></remarks>
Function getAverageTestScore(ByVal scores() As Double)
Dim sum As Double = 0
For i As Integer = 0 To 3
sum += scores(i)
Next
Return sum / 4
End Function
''' <summary>
''' gets letter
''' </summary>
''' <param name="average"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function getLetter(ByVal average As Double) As Char
If average >= 90 Then
Return "A"
End If
If average >= 80 Then
Return "B"
End If
If average >= 70 Then
Return "C"
End If
If average >= 60 Then
Return "D"
End If
Return "F"
End Function
End Module
Comments
Leave a comment