Programming Visual Basic 2010 Please post correct answer. Some of the questions
ID: 3690350 • Letter: P
Question
Programming Visual Basic 2010
Please post correct answer. Some of the questions I asked answered wrong before.
Number Analysis: Create an application that reads the numbers from the file named NumberSet.txt .Your application should perform the following:
1) Display the total of the numbers
2) Display the average of the numbers
3) Display the highest number in the file.
4) Display the lowest number in the file.
Attachment: NumberSet.txt http://s000.tinyupload.com/?file_id=00184765431250246674
I need full programming code with all the comments and naming conventions.
Explanation / Answer
plz check it let me know your comments
Module Module1
Sub Main()
' declear veriables
Dim totalNumbers As Double = 0, avgNumbers As Double
' How to: Write to a Text File. You can change the path and
' file name to substitute text files of your own.
' Read each line of the file into a string array. Each element
' of the array is one line of the file.
Dim Numbers As String() = System.IO.File.ReadAllLines("C:UsersKWVDocumentsisual studio 2012ProjectsConsoleApplication6ConsoleApplication6NumberSet.txt")
' convert string array to double array
Dim doubleAryNumbers As Double() = Array.ConvertAll(Numbers, New Converter(Of String, Double)(AddressOf DoubleConverter))
'Dim cNumbers As Double() = Array.ConvertAll(Numbers, [Double].Parse)
' add numbers the file contents by using a foreach loop.
For Each Number As String In Numbers
totalNumbers = totalNumbers + Convert.ToDouble(Number)
Next
'calculate average total numbers
avgNumbers = totalNumbers / Numbers.Count()
'dispaly total of the numbers
System.Console.WriteLine("the total of the numbers: " & totalNumbers)
'dispaly average of the numbers
System.Console.WriteLine("the average of the numbers: " & avgNumbers)
'dispaly highest number in the file
System.Console.WriteLine("the highest number in the file: " & doubleAryNumbers.Max())
'dispaly lowest number in the file
System.Console.WriteLine("the lowest number in the file: " & doubleAryNumbers.Min())
System.Console.ReadKey()
End Sub
'convert string to double function
Private Function DoubleConverter(ByVal text As String) As Double
Dim value As Double = 0
Double.TryParse(text, value)
Return value
End Function
End Module
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.