Public Class
Modul5
'kamus data
global
Dim
NIM(100) As String
Dim
Nama(100) As String
Dim
Kelas(100) As String
Dim
Nilai(100) As Integer
Dim convert
As String
Dim i As Integer = 0
Dim hitung As Integer
'method
'mencari
rata-rata
Public Function ratarata() As
Double
If (i
> 0) Then
Dim
tampung As Integer
= 0
Dim
hasil As Double
For
j = 0 To 100
tampung = tampung + Nilai(j)
Next
hasil = tampung / i
Return
hasil
Else
convert = i
Return
convert
End If
End Function
'untuk mencari
nilai terbesar
Public Function nilaiterbesar() As
Integer
Dim b,
k, m As Integer
Dim
CopyArray(100) As Integer
For m =
0 To 100
CopyArray(m) = Nilai(m)
Next
k = 0
For b =
0 To i
For
k = 0 To i
If
CopyArray(k) > CopyArray(k + 1) Then
tukar(CopyArray(k),
CopyArray(k + 1))
End
If
Next
Next
Return
CopyArray(k)
End Function
'prosedure tukar
Public Sub tukar(ByRef a As Integer, ByRef b As Integer)
Dim tmp
As Integer
tmp = b
b = a
a = tmp
End Sub
'hitung nilai
terkecil
Public Function nilaiterkecil() As
Integer
Dim
kecil, l As Integer
kecil = 0
For l = 0 To i
If
l = 0 Then
kecil = Nilai(0)
Return
kecil
ElseIf
kecil > Nilai(l) Then
kecil = Nilai(l)
Return
kecil
End
If
Next
End Function
'bersihkan form
Public Sub Clear()
TBnim.Text = ""
TBnama.Text = ""
TBkelas.Text = ""
TBnilai.Text = ""
End Sub
'perintah buton
'menambah data
(buton tambah)
Private Sub BTNtambah_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BTNtambah.Click
NIM(i) = TBnim.Text
Nama(i) = TBnama.Text
Kelas(i) = TBkelas.Text
Nilai(i) = TBnilai.Text
Clear()
i = i + 1
hitung = i
End Sub
'buton hitung
Private Sub BTNhitung_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BTNhitung.Click
TBratarata.Text = ratarata()
TBterbesar.Text = nilaiterbesar()
TBterkecil.Text = nilaiterkecil()
TBjmlmhsw.Text = i
End Sub
'melihat data
sebelumnya (buton prev)
Private Sub BTNprev_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BTNprev.Click
If
(hitung > 0) Then
TBnim.Text = NIM(hitung - 1)
TBnama.Text = Nama(hitung - 1)
TBkelas.Text = Kelas(hitung - 1)
TBnilai.Text = Nilai(hitung - 1)
hitung = hitung - 1
Else
TBnim.Text = NIM(0)
TBnama.Text = Nama(0)
TBkelas.Text = Kelas(0)
TBnilai.Text = Nilai(0)
End If
End Sub
'melihat data
sesudahnya (buton next)
Private Sub BTNnext_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BTNnext.Click
If
(hitung < i) Then
TBnim.Text = NIM(hitung + 1)
TBnama.Text = Nama(hitung + 1)
TBkelas.Text = Kelas(hitung + 1)
TBnilai.Text = Nilai(hitung + 1)
hitung = hitung + 1
Else
TBnim.Text = NIM(i)
TBnama.Text = Nama(i)
TBkelas.Text = Kelas(i)
TBnilai.Text = Nilai(i)
End If
End Sub
'hapus semua data
Private Sub BTNclear_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BTNclear.Click
Dim idx
As Integer
Dim
tmpNIM(100) As String
Dim
tmpNama(100) As String
Dim
tmpKelas(100) As String
Dim
tmpNilai(100) As Integer
Clear()
For idx
= 0 To 100
NIM(idx) = tmpNIM(idx)
Nama(idx) = tmpNama(idx)
Kelas(idx) = tmpKelas(idx)
Nilai(idx) = tmpNilai(idx)
Next
TBratarata.Text = ""
TBterbesar.Text = ""
TBterkecil.Text = ""
TBjmlmhsw.Text = ""
i = 0
End Sub
Private Sub BTNexit_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BTNexit.Click
Me.Close()
End Sub
End Class
Data
Masukan
Hasil
Hitung Hasil
Clear
Analisa
Code
Pada program digunakan array untuk
memaipulasi penyimpanan sementara agar
bisa digunakan untuk menghitung nilai rata rata dengan menampung semua nilai
yang disimpan dan ditambah kan, lalu dibagi dengan jumlah data. Lalu ada
mencari nilai terbesar dengan mencari dari array 0 dan membandingkan nya dengan
array selanjutnya begitupun dengan menentukan nilai terkecil, dan menghitung
jumlah data berdasarkan berapa data yang dimasukan dan juga data yang dihapus.
0 Response to "PEMROGRAMAN DATABASE DAN MANIPULASI"
Post a Comment