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

create a interactive Winform program to calculate the area and volume of some sp

ID: 3687474 • Letter: C

Question

create a interactive Winform program to calculate the area and volume of some spherical shapes, specifically a circle, a sphere and a cylinder. The two inputs are the radius and the height. If the height is zero you are to calculate the area and volume of a circle and a sphere. If the height is greater than zero than you are to calculate only the area and volume of a cylinder.

You should create three classes: one for sphere, one for circle and one for cylinder. Methods and attributes unique to the geometric shapes should be part of that respective class.

Additionally, the radius should be constrained between 0 and 50 and the height should be constrained between 0 and 100.


Im using visual studio 2015. Code Language is: Visual Basic

Explanation / Answer

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim o As New circle
Dim o1 As New sphere
Dim o2 As New cylinder

Dim r, h As Integer
r = Val(TextBox1.Text)
h = Val(TextBox2.Text)

If h = 0 Then
o.area(r)
o.volumn(r)
o1.area(r)
o1.volumn(r)
Else
o2.area(r, h)
o2.volumn(r, h)
End If
End Sub
End Class
Public Class circle
Public Sub area(ByVal r As Integer)
MsgBox(r * r * 3.142)

End Sub

Public Sub volumn(ByVal r As Integer)
MsgBox(2 * r * 3.142)

End Sub

End Class

Public Class sphere
Public Sub area(ByVal r As Integer)
MsgBox(4 * r * r * 3.142)

End Sub

Public Sub volumn(ByVal r As Integer)
MsgBox((4 / 3) * r * r * r * 3.142)

End Sub

End Class
Public Class cylinder
Public Sub area(ByVal r As Integer, ByVal h As Integer)
MsgBox(2 * h * r * 3.142)

End Sub

Public Sub volumn(ByVal r As Integer, ByVal h As Integer)
MsgBox(r * r * 3.142 * h)

End Sub

End Class