Answer to Question #253041 in Algorithms for Israel

Question #253041

create a flowchart that will 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
Expert's answer
2021-10-22T16:44:49-0400
using System;
using System.Collections.Generic;


namespace App
{


    class Program
    {


        static double calculateAreaCircle(double radius)
        {
            return Math.PI * radius * radius;
        }
        static double calculateAreaRectangle(double length, double width)
        {
            return length * width;
        }
        static double calculateAreaCylinder(double radius, double height)
        {
            return Math.PI * radius * radius * height;
        }


        static void Main(string[] args)
        {
            int choice = 1;
            double radius, length, width, height;
            double area = 0;




            while (choice != 4)
            {




                Console.Write("Input 1 for area of circle\n");
                Console.Write("Input 2 for area of rectangle\n");
                Console.Write("Input 3 for area of cylinder\n");
                Console.Write("Input 4 to exit\n");
                Console.Write("Input your choice : ");
                choice = Convert.ToInt32(Console.ReadLine());


                switch (choice)
                {
                    case 1:
                        Console.Write("Input radius of the circle: ");
                        radius = Convert.ToDouble(Console.ReadLine());
                        area = calculateAreaCircle(radius);
                        Console.Write("The area is of the circle: {0}\n", area);
                        break;
                    case 2:
                        Console.Write("Input length of the rectangle: ");
                        length = Convert.ToDouble(Console.ReadLine());
                        Console.Write("Input width of the rectangle: ");
                        width = Convert.ToDouble(Console.ReadLine());
                        area = calculateAreaRectangle(length, width);
                        Console.Write("The area is of the rectangle: {0}\n", area);
                        break;
                    case 3:
                        Console.Write("Input the radius of the cylinder:");
                        radius = Convert.ToDouble(Console.ReadLine());
                        Console.Write("Input the hight of the cylinder:");
                        height = Convert.ToDouble(Console.ReadLine());
                        area = calculateAreaCylinder(radius, height);
                        Console.Write("The area is of the cylinder: {0}\n", area);
                        break;
                    case 4:
                        //exit
                        break;
                }
               
            }


        }


    }
}








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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS