Exercise
Statistics V2
Objetive
Write a Visual Basic (VB.Net) statistical program which will allow the user to:
- Add new data
- See all data entered
- Find an item, to see whether it has been entered or not
- View a summary of statistics: amount of data, sum, average, maximum, minimum
- Exit the program
These options must appear as a menu. Each option will be chosen by a number or a letter.
Create a statistical program which will allow the user to:
- Add new data
- See all data entered
- Find an item, to see whether it has been entered or not
- View a summary of statistics: amount of data, sum, average, maximum, minimum
- Exit the program
These options must appear as a menu. Each option will be chosen by a number or a letter.
The program must reserve space for a maximum of 1000 data, but keep count of how many data actually exist.
Code
Imports System
Public Class exercise78
Public Shared Sub Main()
Dim numbers As Single() = New Single(999) {}
Dim count As Integer = 0
Dim max As Single = 0.0F, min As Single = 0.0F, total As Single = 0.0F, searchNumber As Single = 0.0F
Dim found As Boolean
Dim [option] As Integer = 0
Do
Console.WriteLine("1. Add")
Console.WriteLine("2. Show")
Console.WriteLine("3. Search")
Console.WriteLine("4. Statistics")
Console.WriteLine("5. Exit")
[option] = Convert.ToInt32(Console.ReadLine())
If [option] <> 5 Then
Select Case [option]
Case 1
Console.WriteLine("Enter a number: ")
numbers(count) = Convert.ToSingle(Console.ReadLine())
max = numbers(count)
min = numbers(count)
total += numbers(count)
count += 1
If max < numbers(count) Then max = numbers(count)
If min > numbers(count) Then min = numbers(count)
Case 2
For i As Integer = 0 To count - 1
Console.WriteLine("{0} ", numbers(i))
Next
Case 3
Console.WriteLine("Enter a number for search: ")
searchNumber = Convert.ToSingle(Console.ReadLine())
For i As Integer = 0 To count - 1
If numbers(i) = searchNumber Then found = True
Next
If found Then
Console.WriteLine("Number {0} found a amount of {1} ", numbers(i))
Else
Console.WriteLine("Not found")
found = False
End If
Case 4
Console.WriteLine("Total data: {0}", count + 1)
Console.WriteLine("Sum: {0}", total)
Console.WriteLine("Average: {0}", total / (count + 1))
Console.WriteLine("Min number: {0}", min)
Console.WriteLine("Max number: {0}", max)
Case Else
Console.WriteLine("Error, option 1-5")
End Select
End If
Loop While [option] <> 5
End Sub
End Class