Copy cái này vô Module
Module Module1
Sub Main()
Dim arr(5) As Class1
Dim kqt As Integer
For i As Integer = 0 To 4
arr(i) = New Class1
arr(i).nhap()
Next
Console.WriteLine("Ho Ten Nam Sinh Trong Luong Chieu cao Suc Khoe ")
For i As Integer = 0 To 4
kqt = arr(i).ttsk()
arr(i).xuattal()
If kqt = 1 Then
Console.WriteLine(" Map")
ElseIf kqt = -1 Then
Console.WriteLine(" Om")
Else
Console.WriteLine(" Binh thuong")
End If
Next
Console.ReadLine()
End Sub
End Module
Copy vô class
Public Class Class1
Private hoten As String
Private namsinh As Integer
Private chieucao As Double
Private trongluong As Double
Public Sub New()
hoten = "N/A"
namsinh = 0
chieucao = 0
trongluong = 0
End Sub
Public Sub nhap()
Console.Write("Nhap vao ho ten :")
hoten = Console.ReadLine()
Console.Write("Nhap vao nam sinh {0} :", hoten)
namsinh = Console.ReadLine()
Console.Write("Nhap vao chieu cao (cm){0} :", hoten)
chieucao = Console.ReadLine()
Console.Write("Nhap vao can nang (Kg){0} :", hoten)
trongluong = Console.ReadLine()
End Sub
Public Sub xuattal()
Console.Write("{0} {1} {2} {3} ", hoten, namsinh, chieucao, trongluong)
End Sub
Public Sub xuat()
Dim tuoi As Integer
tuoi = Date.Now.Year - namsinh
Console.Clear()
Console.WriteLine("Ten :{0}", hoten)
Console.WriteLine("Nam sinh :{0} Tuoi{1}", namsinh, tuoi)
Console.WriteLine("Chieu cao(cm):{0}", chieucao)
Console.WriteLine("Can nang(Kg) :{0}", trongluong)
End Sub
Public Function ttsk() As Integer
Dim k As Double
k = trongluong / Math.Pow(chieucao, 2)
If 15 <= k And k <= 25 Then
Return 0
ElseIf k > 25 Then
Return 1
Else
Return -1
End If
End Function
End Class
Không có nhận xét nào:
Đăng nhận xét