-Using/creating 4 VB Classes, create a single Windows Form application to calcul
ID: 3679286 • Letter: #
Question
-Using/creating 4 VB Classes, create a single Windows Form application to calculate the centroid and area of the 3 common shapes: Triangle, Circle and Rectangle
-Create a Base (Parent) Class named clsShape containing 3 properties (Base, Height, Diameter)
-Create an additional 3 derived sub-classes named clsSquare, clsTriangle, clsCircle which Inherits the properties of the Base Class. For each of the derived classes, create 3 methods (functions) calculate the centroid (X and Y) and the Area
-In a Windows Form 1, create an instance (object) for each derived class named objSquare, objTriangle, objCircle
For example: Dim objSquare as New clsSquare
Using/creating 4 VB Classes, create a single Windows Form application to calculate the centroid and area of the 3 common shapes below: Right Triangle Rectang The centroid of a square or rectangle is The centroid of a right triangle is located at a located at a distance of 1/2 its height and 1/2 distance of 113 its height and 1/3 its base. H Centroid Area (b)(h) Area b)(h both Cx d Cy 3r Area A-TD Class Diagram Base Single Properties Height Single Diameter Single CenX 0: Single Area): Single Area0C Single CentX0 Area Single Create a Base (Parent) Class named clsshape containing 3 properties (Base, Height, Diameter) Create an additional 3 derived sub-classes named clsSquare, clsTriangle, cls circle which Inherits the properties of the Base Class. For each of the derived classes, create 3 methods (functions) calculate the centroid (X and Y) and the Area In a Windows Form 1, create an instance (object) for each derived class named bis obiTriangle, bici For example: DimobiSquare as New clsSquare he V Studio S Solution Explorer Search Solution Explorer (Ctrl+:) Windows Ap My Project nfig VB clsCircle.vb D vB gle.vb D clsTriangle.vb Sample Windows Form oop Application forcentroids and Area Enter Base Value Enter Height Value Enter Diameter Value Cent Cent Cert (P) Cert CertExplanation / Answer
Base Class and derived class is given below:
Class clsShape
Protected Base As Integer
Protected Height As Integer
Protected Diameter As Integer
Public Sub setBase(ByVal b As Integer)
Base = b
End Sub
Public Sub setHeight(ByVal h As Integer)
Height = h
End Sub
Public Sub setDiameter(ByVal d As Integer)
Diameter = d
End Sub
End Class
Class clsSquare : Inherits clsShape
Public Function Area() As Integer
Return (Base * Height)
End Function
Public Function CentX() As Integer
Return (Base/2)
End Function
Public Function CentY() As Integer
Return (Height/2)
End Function
End Class
Class clsTriangle : Inherits clsShape
Public Function Area() As Integer
Return ((Base * Height)/2)
End Function
Public Function CentX() As Integer
Return (Base/3)
End Function
Public Function CentY() As Integer
Return (Height/3)
End Function
End Class
Class clsCircle : Inherits clsShape
Public Function Area() As Integer
Return ((22/7)*(Diameter/2))
End Function
Public Function CentX() As Integer
Return (Diameter/2))
End Function
Public Function CentY() As Integer
Return (Diameter/2))
End Function
End Class
Class ShapeTest
Shared Sub Main()
Dim objSquare As clsSquare = New clsSquare()
objSquare.setBase(10);
objSquare.setHeight(10);
objSquare.Area();
objSquare.CentX();
objSquare.CentY();
Dim objTriangle As clsTriangle = New clsTriangle()
objTriangle.setBase(10);
objTriangle.setHeight(5);
objTriangle.Area();
objTriangle.CentX();
objTriangle.CentY();
Dim objCircle As clsCircle = New clsCircle()
objCircle.setDiameter(10);
objCircle.Area();
objCircle.CentX();
objCircle.CentY();
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.