用VB编辑(定义一个三角形类,要求有底,高两个属性,一个求面积的方法,从键盘输入底和高,求其类对象的面积)

来源:百度知道 编辑:UC知道 时间:2024/05/17 03:33:14
用VB进行编辑

ClsTriangle
---------------------------------------------------------
Private mHeight As Double
Private mWidth As Double

Public Property Get Height() As Double
Height = mHeight
End Property

Public Property Let Height(ByVal vNewValue As Double)
mHeight = vNewValue
End Property

Public Property Get Width() As Double
Width = mWidth
End Property

Public Property Let Width(ByVal vNewValue As Double)
mWidth = vNewValue
End Property

Public Function GetArea()
GetArea = mHeight * mWidth / 2
End Function

Form
-----------------------------------------------------------
Private Sub Command1_Click()
Dim t As New ClsTriangle
t.Height = InputBox("输入三角形的高")
t.Width = InputBox("输入三角形的底")
MsgBox "面积是" & t.GetArea
End Sub