Answer to Question #179529 in Visual Basic for anna

Question #179529

 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]


1
Expert's answer
2021-04-08T12:39:31-0400
Module Module1


    Sub Main()
        'The program should store each student’s information in the arrays 
        'array of string objects to hold the five student names
        Dim names(4) As String
        'an array of one character to hold the five students’ letter grades
        Dim letterGrades(4) As Char
        'five arrays of doubles to hold each student’s set of test scores and average score. 
        Dim testScores1(3) As Double
        Dim testScores2(3) As Double
        Dim testScores3(3) As Double
        Dim testScores4(3) As Double
        Dim testScores5(3) As Double
        Dim averageScore(4) As Double
        Console.Write("Enter the student name 1: ")
        names(0) = Console.ReadLine()
        testScores1 = getScores(names(0))
        Console.Write("Enter the student name 2: ")
        names(1) = Console.ReadLine()
        testScores2 = getScores(names(1))
        Console.Write("Enter the student name 3: ")
        names(2) = Console.ReadLine()
        testScores3 = getScores(names(2))
        Console.Write("Enter the student name 4: ")
        names(3) = Console.ReadLine()
        testScores4 = getScores(names(3))
        Console.Write("Enter the student name 5: ")
        names(4) = Console.ReadLine()
        testScores5 = getScores(names(4))
        'calculate the average test score
        averageScore(0) = calculateAverageTestScore(testScores1)
        averageScore(1) = calculateAverageTestScore(testScores2)
        averageScore(2) = calculateAverageTestScore(testScores3)
        averageScore(3) = calculateAverageTestScore(testScores4)
        averageScore(4) = calculateAverageTestScore(testScores5)


        For i As Integer = 0 To 4
            letterGrades(i) = getLetterGrades(averageScore(i))
        Next


        'calculate and display each student’s average test score 
        'and a letter grade based on the average. 
        For i As Integer = 0 To 4
            Console.WriteLine("The average test score for student " + names(i) + ": " + averageScore(i).ToString())
            Console.WriteLine("The letter grade for student " + names(i) + ": " + letterGrades(i).ToString() + vbNewLine)
        Next
        Console.ReadLine()
    End Sub
    ''' <summary>
    ''' The program should allow the user to enter each student’s name and his or her four test scores. 
    ''' </summary>
    ''' <param name="studentName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function getScores(ByVal studentName As String)
        Dim testScores(3) As Double
        Console.WriteLine("Enter the test score for the student " + studentName)
        For i As Integer = 0 To 3
            'Input Validation: Do not accept test scores less than 0 or greater than 10
            testScores(i) = -1
            While testScores(i) < 0 Or testScores(i) > 100
                Console.Write("Enter the test score " + (i + 1).ToString() + " [0-100]: ")
                testScores(i) = Double.Parse(Console.ReadLine())
            End While
        Next
        Console.WriteLine()
        Return testScores
    End Function
    ''' <summary>
    ''' Calculates average test score
    ''' </summary>
    ''' <param name="testScores"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function calculateAverageTestScore(ByVal testScores() As Double)
        Dim sumTestScore As Double = 0
        For i As Integer = 0 To 3
            sumTestScore += testScores(i)
        Next
        Return sumTestScore / 4.0
    End Function
    ''' <summary>
    ''' get letter grades
    ''' </summary>
    ''' <param name="averageScore"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function getLetterGrades(ByVal averageScore As Double) As Char
        If averageScore >= 90 Then
            Return "A"
        End If
        If averageScore >= 80 Then
            Return "B"
        End If
        If averageScore >= 70 Then
            Return "C"
        End If
        If averageScore >= 60 Then
            Return "D"
        End If


        Return "F"
    End Function


End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
09.04.21, 20:18

Dear Veronika, please use panel for submitting new questions

Veronika
09.04.21, 20:07

your answer helps me but, I don't understand why the average for student 5 is 0.. can you please explain?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS