Advertisement
Guest User

Shapes Area

a guest
Jan 20th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ShapeProgram
  8. {
  9.     class shape
  10.     {
  11.         public double width, hight, radius, axis;
  12.     }
  13.     class Circle : shape
  14.     {
  15.         public void CalculateCircle(double radius)
  16.         {
  17.             double Area = 22 / 7 * radius * radius;
  18.             Console.WriteLine("Area = {0}", Area);
  19.         }
  20.     }
  21.     class Square : shape
  22.     {
  23.         public void CalculateSquare(double axis)
  24.         {
  25.             double Area = axis * axis;
  26.             Console.WriteLine("Area = {0}", Area);
  27.         }
  28.     }
  29.     class Rectangle : shape
  30.     {
  31.         public void CalculateRectangle(double width, double hight)
  32.         {
  33.             double Area = (width + hight) * 2;
  34.             Console.WriteLine("Area = {0}", Area);
  35.         }
  36.     }
  37.     class Program
  38.     {
  39.         static void Main(string[] args)
  40.         {
  41.             Console.Write("Choose from\n1- Circle\n2- Square\n3- Rectangle\n");
  42.             int n = int.Parse(Console.ReadLine());
  43.             switch (n)
  44.             {
  45.                 case 1:
  46.                     {
  47.                         Circle cr = new Circle();
  48.                         Console.Write("Enter Raduis of Circle : ");
  49.                         cr.radius = double.Parse(Console.ReadLine());
  50.                         cr.CalculateCircle(cr.radius);
  51.                     }
  52.                     break;
  53.                 case 2:
  54.                     {
  55.                         Square sq = new Square();
  56.                         sq.axis = double.Parse(Console.ReadLine());
  57.                         sq.CalculateSquare(sq.axis);
  58.                     }
  59.                     break;
  60.                 case 3:
  61.                     {
  62.                         Rectangle rec = new Rectangle();
  63.                         Console.Write("Enter Hight of Rectangle : ");
  64.                         rec.hight = double.Parse(Console.ReadLine());
  65.                         Console.Write("Enter Width of Rectangle : ");
  66.                         rec.width = double.Parse(Console.ReadLine());
  67.                         rec.CalculateRectangle(rec.hight, rec.width);
  68.                     }
  69.                     break;
  70.                 default:
  71.                     Console.WriteLine("error");
  72.                     break;
  73.             }
  74.             Console.ReadKey();
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement