Computer Science(9608) notes and Resources
Module Module1
Sub Main()
Dim number, counter As Integer 'storing 10 number in a file
Dim arnumber(10) As Integer
Dim fwrite As New IO.StreamWriter("d:\number.txt", True)
Console.WriteLine("Enter any numbers: ")
For counter = 1 To 10
number = Console.ReadLine()
fwrite.WriteLine(number)
Next
fwrite.Close()
Dim lineoftext As String 'copying number from file to an integer array
Dim fread As New IO.StreamReader("d:\number.txt")
For counter = 1 To 10
lineoftext = fread.ReadLine()
arnumber(counter) = Val(lineoftext)
Next
fread.Close()
Dim temp, num As Integer 'bubble sorting
Dim counter1 As Integer
num = 9
For counter = 1 To 9
For counter1 = 1 To num
If arnumber(counter1) > arnumber(counter1 + 1) Then
temp = arnumber(counter1)
arnumber(counter1) = arnumber(counter1 + 1)
arnumber(counter1 + 1) = temp
End If
Next
num = num - 1
Next
Dim total As Integer = 0 'largest value
Console.WriteLine("The largest number is " & arnumber(10))
For counter = 1 To 10
total = total + arnumber(counter)
Next
Console.WriteLine("The mean value is " & total / 10) 'mean value
Dim positionformedian As Decimal 'median value
Dim medianvalue As Decimal
Dim tempnum As Integer
positionformedian = (10 + 1) / 2
tempnum = Math.Truncate(positionformedian)
medianvalue = ((arnumber(tempnum) + arnumber(tempnum + 1)) * (positionformedian - tempnum))
Console.WriteLine("the median value is " & medianvalue)
Dim flag As Boolean = True 'mode value
Dim count As Integer = 0
temp = arnumber(1)
For counter = 1 To 10
If flag = False Then
count = 1
temp = arnumber(counter)
flag = True
End If
If temp = arnumber(counter) Then
count = count + 1
Else
flag = False
End If
Next
Console.WriteLine("the mode value is " & temp & " and its frequency is " & count)
Console.ReadLine()
End Sub
End Module
- CIE A-LEVEL COMPUTER SCIENCE ( 9608 )
No comments:
Post a Comment
Comments here....