Using Visual Basic Suppose a teacher has five students who have taken four tests
ID: 3762515 • Letter: U
Question
Using Visual Basic
Suppose a teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores. Test Score Letter Grade 90–100 A 80–89 B 70–79 C 60–69 D 0–59 F Create an application that uses an array of strings to hold the five student names, an array of five strings to hold each student’s letter grades, and five arrays of four single precision numbers to hold each student’s set of test scores. Equip the application with a menu or a set of buttons that allows the application to perform the following: • Display a form that allows the user to enter or change the student names and their test scores. • Calculate and display each student’s average test score and a letter grade based on the average. Input validation: Do not accept test scores less than zero or greater than 100.
Explanation / Answer
Dim message, title, defaultValue As String
Dim myValue As Object
' Set prompt.
message = "Enter a value between 1 and 3"
' Set title.
title = "InputBox Demo"
defaultValue = "1" ' Set default value.
Dim studentNames(0 to 4) As String
Dim studentGrades(0 to 4) As String
Dim sub1(0 to 4) As String
Dim sub2(0 to 4) As String
Dim sub3(0 to 4) As String
Dim sub4(0 to 4) As String
Dim message, title, defaultValue As String
Dim myValue As Object
title = "InputBox Demo"
defaultValue = "1" ' Set default value.
message = "Enter student name"
For Each item As String In studentNames
myValue = InputBox(message, title, defaultValue)
studentNames (item)=myvalue;
Next
message = "Enter sub1 marks"
Dim myValue1 As Object
For Each item As String In studentNames
myValue1 = InputBox(message, title, defaultValue)
sub1 (item)=myvalue1;
Next
Dim myValue2 As Object
For Each item As String In studentNames
myValue2 = InputBox(message, title, defaultValue)
sub2 (item)=myvalue2;
Next
Dim myValue3 As Object
For Each item As String In studentNames
myValue3 = InputBox(message, title, defaultValue)
sub3 (item)=myvalue3;
Next
Dim myValue4 As Object
For Each item As String In studentNames
myValue4 = InputBox(message, title, defaultValue)
sub4 (item)=myvalue4;
Next
Dim total As Object
Dim grade As Object
For Each item As String In studentNames
total = sub1 (item)+ sub2 (item)+ sub3 (item)+ sub4 (item)/4;
If total >= 90 And total <= 100 Then
grade = "A"
ElseIf total >= 80 And total <= 89 Then
grade = "B"
ElseIf total >= 70 And total <= 79 Then
grade = "C"
ElseIf total >= 60 And total <= 69 Then
grade = "D"
Else
grade = "F"
End If
Return grade
studentGrades(item)=grade;
Next
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.