You are to create an interactive program to calculate the area of some spherical
ID: 3684940 • Letter: Y
Question
You are to create an interactive program to calculate the area 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 of a circle and a sphere. If the height is greater than zero than you are to calculate only the area of a cylinder.
create three functions one for each area of the shape. A subroutine should be written to enter the radius and height. Three additional subroutines should be written to display the area of each shape.
Another function should be written for setting a variable called anotherRun. This variable should be error checked to allow only for a 'n' or 'N' or 'y' or 'Y'.
Additionally, the radius should be constrained between 1 and 50 and the height should be constrained between 1 and 100.
A console-based application is required, im using visual studio 2015, Code: Visual basic
Explanation / Answer
Module Module1
Public r, h As Integer
Public Sub getdata()
While (True)
Console.WriteLine("Enter Radius")
r = Convert.ToInt32(Console.ReadLine())
If r > 0 And r < 51 Then
Exit While
End If
End While
While (True)
Console.WriteLine("Enter Height")
h = Convert.ToInt32(Console.ReadLine())
If h > 0 And h < 101 Then
Exit While
End If
End While
End Sub
Public Sub cirarea()
Dim a As Double
a = r * r * 3.142
Console.WriteLine("Area of Circle is = " & a)
End Sub
Public Sub spearea()
Dim a As Double
a = r * r * 3.142 * 4
Console.WriteLine("Area of Sphere is = " & a)
End Sub
Public Sub cylarea()
Dim a As Double
a = (r * r * 3.142 * 2) + (a * 3.142 * r * h)
Console.WriteLine("Area of Cylinder is = " & a)
End Sub
Sub Main()
getdata()
cirarea()
spearea()
cylarea()
Console.ReadKey()
End Sub
End Module
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.