Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using/creating 4 VB Classes, create a single Windows Form application to calcula

ID: 3677399 • Letter: U

Question

Using/creating 4 VB Classes, create a single Windows Form application to calculate the centroid and area of the 3 common shapes below: Create a Base (Parent) Class named clsShape containing 3 properties (Base, Height, Diameter) Create an additional 3 derived sub-classes named clsSquare, cIsTriangle, 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

Explanation / Answer

Program to find the area of a square:-

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

Class Shape

   Protected width As Integer

   Protected height As Integer

   Public Sub setWidth(ByVal w As Integer)

      width = w/2

   End Sub

   Public Sub setHeight(ByVal h As Integer)

      height = h/2

   End Sub

End Class

' Derived class

Class Square : Inherits Shape

   Public Function getArea() As Integer

      Return (width * height)

   End Function

End Class

Class SquareTester

   Shared Sub Main()

      Dim objSquare As New clsSquare = New objSquare()

      objSquare.setWidth(w)

     objSquare.setHeight(h)

      ' Print the area of the object.

      Console.WriteLine("Total area: {0}", objSquare.getArea())

      Console.ReadKey()

   End Sub             

End Class

In the above program to find the area of a circle and triangle repalce in the place of square as circle if it is a circle otherwise replace with triangle.

Triangle:-Width=width

height=height

area=0.5*width*height

Circle:-Width=width/3

height=height/3

area=3.14*width*height