107 311
Assignments Done
98.9%
Successfully Done
In March 2023

# Answer to Question #253031 in C# for Israel

Question #253031

Write an application that computes the area of a circle, rectangle, and cylinder. Display a menu showing the three options. Allow users to input which figure they want to see calculated. Based on the value inputted, prompt for appropriate dimensions and perform the calculations and perform the calculations using the following formulas:

Area of a circle = pi*radius2

Area of a rectangle = length*width

Area of a cylinder = pi*radius2*height

Write a modularized solution, which includes class methods for inputting data and performing calculations.

1
2021-10-18T10:53:24-0400
using System;

namespace Question
{
abstract class Figure
{
public abstract double Area();
}

class Circle : Figure
{
public double Radius { get; set; }
public override double Area()
{
}
}
class Rectangle : Figure
{
public double Length { get; set; }
public double Width { get; set; }

public override double Area()
{
return Length * Width;
}
}
class Cylinder : Figure
{
public double Radius { get; set; }
public double Height { get; set; }

public override double Area()
{
}
}
class Program
{
{
Console.WriteLine("1 - Circle");
Console.WriteLine("2 - Rectangle");
Console.WriteLine("3 - Cylinder");
Console.WriteLine();
}
static int SelectFigure()
{
}
static Figure GetFigure(int selectedFigure)
{
if (selectedFigure == 1)
return new Circle();
if (selectedFigure == 2)
return new Rectangle();
return new Cylinder();
}
static void InputCircleData(Circle circle)
{
}
static void InputRectangleData(Rectangle rectangle)
{
Console.Write("length = ");

Console.Write("width = ");
}
static void InputCylinderData(Cylinder cylinder)
{

Console.Write("height = ");
}
static void InputFigureData(Figure figure)
{
if (figure is Circle)
InputCircleData((Circle)figure);
else if (figure is Rectangle)
InputRectangleData((Rectangle)figure);
else
InputCylinderData((Cylinder)figure);
}
static void Main(string[] args)
{
int selectedFigure = SelectFigure();

if (selectedFigure >= 1 && selectedFigure <= 3)
{
Figure figure = GetFigure(selectedFigure);
InputFigureData(figure);
Console.WriteLine();

Console.WriteLine(string.Format("Area = {0}", figure.Area()));
}
else
Console.WriteLine("Invalid choice");

Console.WriteLine();

Console.WriteLine();
}
}
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!