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

Question: Write an application that computes the area of a circle, rectangle, an

ID: 3633420 • Letter: Q

Question

Question: 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 using the following formulas:
Area of circle = pi * radius ^ 2
Area of rectangle = length * width
Area of cylinder 2 * pi * radius ^ 2 + 2 * pi * radius * height
Write a modularized solution, which includes class methods for inputting data and performing calculations. (hint: you will work everything inside the same class where the Main is located).

I assume I'd have to create three classes, but beyond that I'm not sure about how to proceed.


Explanation / Answer

using System;
using System.Collections.Generic;
using System.Text;

namespace Geometric
{
    class Program
    {
        static void Main(string[] args)
        {
            int shapeoption = -1;
            while (true)
            {
                Console.WriteLine(" Shapes : ");
                Console.WriteLine("1. Circle");
                Console.WriteLine("2. Rectangle");
                Console.WriteLine("3. Sphere");
                Console.WriteLine("4. Exit");
                Console.WriteLine("Choose an option to compute>> ");
                shapeoption = Int32.Parse(Console.ReadLine());
                switch (shapeoption)
                {
                    case 1:
                        double area = CircleInput();
                        Console.WriteLine("The area of the circle is : " + area);
                        break;
                    case 2:
                        area = RectangleInput();
                        Console.WriteLine("The area of the rectangle is : " + area);
                        break;
                    case 3:
                        area = SphereInput();
                        Console.WriteLine("The area of the Cylinder is : " + area);
                        break;
                    case 4:
                        return;
                        break;
                    default:
                        Console.WriteLine("Error : Invalid option");
                        break;
                }
            }
            Console.Read();
        }

        public static double CircleInput()
        {
            double rad=0.0;
            Console.WriteLine("Enter radius of the circle : ");
            rad = Double.Parse(Console.ReadLine());
            rad = CircleArea(rad);
            return rad;
        }

        public static double CircleArea(double rad)
        {
            return Math.PI * rad * rad;
        }

        public static double RectangleInput()
        {
            double len, width;
            Console.WriteLine("Enter length of the Rectangle : ");
            len = Double.Parse(Console.ReadLine());
            Console.WriteLine("Enter width of the Rectangle : ");
            width = Double.Parse(Console.ReadLine());
            return RectArea(len,width);
        }

        public static double RectArea(double length, double width)
        {
            return length * width;
        }

        public static double SphereInput()
        {
            double rad, height;
            Console.WriteLine("Enter radius of the Cylinder : ");
            rad = Double.Parse(Console.ReadLine());
            Console.WriteLine("Enter height of the Cylinder : ");
            height = Double.Parse(Console.ReadLine());
            return SphereArea(rad, height);
        }

        public static double SphereArea(double rad, double height)
        {
            return 2 * Math.PI * rad * (rad + height);
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote