write a programming code for the following problem using Visual Basic Studio VB.
Below is the solution:
code:
Public Class frmMain
Dim number As String 'declare string
variable
Dim n As Integer 'declare integer variable
Dim intNumbers(100) As Integer ' declare
array
Dim count As Integer = 0
Private Sub frmMain_Load(sender As Object, e
As EventArgs) Handles MyBase.Load
'disable the
textbox
txtCount.Enabled =
False
txtSum.Enabled =
False
txtAverage.Enabled =
False
txtMaximum.Enabled =
False
txtMinimum.Enabled =
False
txtNegativeCount.Enabled
= False
txtEvenCount.Enabled =
False
'center on
screen
CenterToScreen()
End Sub
Private Sub btnEnterNumber_Click(sender As
Object, e As EventArgs) Handles btnEnterNumber.Click
number = InputBox("Enter
a number (integer 'x' to stop adding numbers)", "Input List") 'inut
box to input number
If number.Equals("x")
Then 'check for the input x
btnEnterNumber.Enabled = False
ElseIf
number.Equals("X") Then 'check for the input X
btnEnterNumber.Enabled = False
Else
If Integer.TryParse(number, n) Then 'check for the input
integer
lstNumber.Items.Add(n) 'add item to the list
Else 'if input is not integer
MessageBox.Show("Enter correct number")
End If
End If
End Sub
Private Sub btnCompute_Click(sender As
Object, e As EventArgs) Handles btnCompute.Click
'declare variable
Dim sum As Integer =
0
Dim avg As Double
Dim evenCount As Integer
= 0
Dim negativeCount As
Integer = 0
'loop through each item
of the listbox
For Each item In
lstNumber.Items
sum += item 'sum
intNumbers(count) = item 'insert each items into array
count += 1 'count the items of the list box
Next
Dim intMin As Integer
= Integer.MaxValue, intMax As Integer = Integer.MinValue, Value As
Integer = 0
'Loop to find the
minimum and the maximum value in the array and the sum of all the
value in the array
For i = 0 To count -
1
Value = intNumbers(i)
If Value < intMin Then 'check fo the minimum number
intMin = Value
End If
If Value > intMax Then 'check fo the maximum number
intMax = Value
End If
If (Value Mod 2 = 0) Then 'if for the even number check
evenCount += 1 'count even
End If
If (Value < 0) Then 'if for the negative value check
negativeCount += 1 'count negative
End If
Next
avg = sum / count 'calculate the average
'display each items
to the textbox
txtCount.Text =
lstNumber.Items.Count
txtSum.Text = sum
txtAverage.Text =
avg
txtMaximum.Text =
intMax
txtMinimum.Text =
intMin
txtEvenCount.Text =
evenCount
txtNegativeCount.Text =
negativeCount
'reset the
variable
sum = 0
Value = 0
intMax = 0
intMin = 0
count = 0
avg = 0
evenCount = 0
negativeCount = 0
End Sub
End Class
sample output:
write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mam...