Answer to Question #283377 in C# for kani

Question #283377

Write a program to calculate the perimeter of different shapes using an abstract class.

Sample Input and Output 1:

Shapes

1.Square

2.Rectangle

3.Circle

Enter your choice

1

Enter the side of the square

5.6

Perimeter of square is 22.40


Sample Input and Output 2:

Shapes

1.Square

2.Rectangle

3.Circle

Enter your choice

2

Enter the length of the rectangle

5

Enter the width of the rectangle

6.3

Perimeter of rectangle is 22.60


Sample Input and Output 3:

Shapes

1.Square

2.Rectangle

3.Circle

Enter your choice

3

Enter the radius of the circle

5

Perimeter of circle is 31.40


Sample Input and Output 4:

Shapes

1.Square

2.Rectangle

3.Circle

Enter your choice

5

Invalid input

 


1
Expert's answer
2021-12-30T01:37:08-0500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace f2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Введите свой выбор: ");
            byte chose = byte.Parse(Console.ReadLine());
            switch (chose)
            {
                case 1: method1(); break;
                case 2: method2(); break;
                case 3: method3(); break;
                default: Console.WriteLine("Некорректный ввод"); break;
            }
            Console.ReadLine();
        }
        static void method1() //периметр квадрата
        {
            Console.Write("Введите сторону квадрата: ");
            var a = double.Parse(Console.ReadLine());
            var P = 4 * a;
            Console.Write("P = " + P);
        }
        static void method2()   //периметр прямоугольника
        {
            Console.Write("Введите длину прямоугольника: ");
            var a=double.Parse(Console.ReadLine());
            Console.Write("Введите ширину прямоугольника: ");
            var b=double.Parse(Console.ReadLine());
            var P = 2 * (a + b);
            Console.Write("Периметр = "+P);

        }
        static void method3() // периметр круг
        {
            Console.Write("Введите радиус круга: ");
            var r = double.Parse(Console.ReadLine());
            var n=3.14;
            var P=2*r*n;
            Console.Write($"Периметр = {P}");
        }

    }
}

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
New on Blog
APPROVED BY CLIENTS