Visual basic 2010 Programs To Accompany Programming Logic and Design 7th edition
ID: 3677281 • Letter: V
Question
Visual basic 2010 Programs To Accompany Programming Logic and Design 7th edition
I need help figuring out this array. It's Lab 6.1 Array Basics.
In this lab, you complete a partially prewritten Visual Basic program that uses an array. The Program prompts the user to interactively enter 10 salaries, which the program stores in an array. It should then find the minmum and maximum salaries stored in the array, as well as the average of the 10 salaries. The data file provided for this lab includes the imput statement and some variable declarations. Comments are included in the file to help you write the remained of the program.
Execute the program using the following 10 values: 45000.00, 22000.00, 6000.00, 100000.00, 57000.00, 1000.00, 90000.00, 12000.00, 6000.00, and 35000.00. The minimum value should be 1000, and the maximum value should be 100000. The average should be 37400.
Option Explicit On
Option Strict On
Module MinMaxSalary
Sub Main()
' Declare a named constant for array size here
' Declare array here
' Use this integer variable as your loop index
Dim loopIndex As Integer
' Use this variable to store the salary input by user
Dim salary As Double
' Declare string version of salary here
Dim salaryString As String
' Use these variables to store the minimim and maximum values
Dim min As Double
Dim max As Double
' Use these variables to store the total and the average
Dim total As Double
Dim average As Double
' Write a loop to get salaries from user and assign to array
For loopIndex = 0 To MAX_SALARIES - 1
salaryString = InputBox$("Enter a salary: ")
salary = Convert.ToDouble(salaryString)
' Assign value to array
Next loopIndex
' Assign the first element in the array to be the minimum and the maximum
min = salaries(0)
max = salaries(0)
' Start out your total with the value of the first element in the array
total = salaries(0)
' Write a loop here to access array values starting with numbers(1)
' Within the loop test for minimum and maximum salaries
' Also accumulate a total of all salaries
' Calculate the average of the 10 salaries
' Print the salaries stored in the salaries array
' Print the maximum value, minimum value, and average
End Sub
End Module
Explanation / Answer
Option Explicit On
Option Strict On
Module MinMaxSalary
Sub Main()
' Declare a named constant for array size here
Dim MAX_SALARIES As Integer = 10
' Declare array here
Dim salaries(size) As Double
' Use this integer variable as your loop index
Dim loopIndex As Integer
' Use this variable to store the salary input by user
Dim salary As Double
' Declare string version of salary here
Dim salaryString As String
' Use these variables to store the minimum and maximum values
Dim min As Double
Dim max As Double
' Use these variables to store the total and the average
Dim total As Double
Dim average As Double
' Write a loop to get salaries from user and assign to array
For loopIndex = 0 To MAX_SALARIES - 1
salaryString = InputBox$("Enter a salary: ")
salary = Convert.ToDouble(salaryString)
' Assign value to array
salaries(loopIndex) = salary
Next loopIndex
' Assign the first element in the array to be the minimum and the maximum
min = salaries(0)
max = salaries(0)
' Start out your total with the value of the first element in the array
total = salaries(0)
' Write a loop here to access array values starting with numbers(1)
for loopIndex = 1 To MAX_SALARIES -1
' Within the loop test for minimum and maximum salaries
If salaries(loopIndex) < min then
Min = salaries(loopIndex)
End If
If salaries(loopIndex) > max then
Max = salaries(loopIndex)
End If
' Also accumulate a total of all salaries
total = total + salaries(loopIndex)
Next loopIndex
' Calculate the average of the 10 salaries
average = total/MAX_SALARIES
' Print the salaries stored in the salaries array
For loopIndex = 0 To MAX_SALARIES
System.Console.WriteLine(salaries(loopIndex))
Next loopIndex
' Print the maximum value, minimum value, and average
System.Console.WriteLine(“minimum value “ & min )
System.Console.WriteLine(“maximum value “ & max)
System.Console.WriteLine(“average value “ & average)
End Sub
End Module
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.