Facebook
From jas, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 91
  1. using System;
  2.  
  3. namespace Assignment_Shape
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             var rectangle = new rectangle();
  11.             Console.Write("Enter Rectangle's Height: ");
  12.             double a = Convert.ToDouble(Console.ReadLine());
  13.             Console.Write("Enter Rectangle's Width : ");          
  14.             double b = Convert.ToDouble(Console.ReadLine());
  15.             rectangle.Area(a,b);
  16.             Console.WriteLine("The rectangle has an area of {0}", rectangle.area);
  17.             Console.WriteLine();
  18.  
  19.             var square = new square();
  20.             Console.Write("Enter Square's Height: ");
  21.             double c = Convert.ToDouble(Console.ReadLine());
  22.             square.Area(c);
  23.             Console.WriteLine("The square has an area of {0}", square.area);
  24.             Console.WriteLine();
  25.  
  26.             var triangle = new triangle();
  27.             Console.Write("Enter Triangle's Height: ");
  28.             double d = Convert.ToDouble(Console.ReadLine());
  29.             Console.Write("Enter Triangle's Base  : ");
  30.             double e = Convert.ToDouble(Console.ReadLine());
  31.             triangle.Area(d, e);
  32.             Console.WriteLine("The triangle has an area of {0}", triangle.area);
  33.             Console.WriteLine();
  34.  
  35.             var rhombus = new rhombus();
  36.             Console.Write("Enter Rhombus first Dimension : ");
  37.             double f = Convert.ToDouble(Console.ReadLine());
  38.             Console.Write("Enter Rhombus second Dimension: ");
  39.             double g = Convert.ToDouble(Console.ReadLine());
  40.             rhombus.Area(f, g);
  41.             Console.WriteLine("The rhombus has an area of {0}", rhombus.area);
  42.             Console.WriteLine();
  43.  
  44.             var pentagon = new pentagon();
  45.             Console.Write("Enter Pentagon's Apothem : ");
  46.             double h = Convert.ToDouble(Console.ReadLine());
  47.             Console.Write("Enter Pentagon's Length  : ");
  48.             double i = Convert.ToDouble(Console.ReadLine());
  49.             pentagon.Area(h, g);
  50.             Console.WriteLine("The pentagon has an area of {0}", pentagon.area);
  51.             Console.WriteLine();
  52.  
  53.             var circle = new circle();
  54.             Console.Write("Enter Circle's Radius : ");
  55.             double j = Convert.ToDouble(Console.ReadLine());
  56.             circle.Area(i);
  57.             Console.WriteLine("The circle has an area of {0}", circle.area);
  58.  
  59.  
  60.         }
  61.  
  62.     }
  63.     class Shape
  64.     {
  65.         public double area { get; set; }
  66.     }
  67.     class rectangle : Shape
  68.     {
  69.         // Return area of the rectangle.
  70.         public void Area(double height, double width)
  71.         {
  72.             area = width * height;
  73.         }
  74.     }
  75.     class square : Shape
  76.     {
  77.         // Return area of the square.
  78.         public void Area(double side)
  79.         {
  80.             area = side * side;
  81.         }
  82.     }
  83.     class triangle : Shape
  84.     {
  85.         // Return area of the triangle.
  86.         public void Area(double height, double basetri)
  87.         {
  88.             area = (basetri * height)/2;
  89.         }
  90.     }
  91.     class rhombus : Shape
  92.     {
  93.         // Return area of the rhombus.
  94.         public void Area(double dimension1, double dimension2)
  95.         {
  96.             area = (dimension1 * dimension2)/2;
  97.         }
  98.     }
  99.     class pentagon : Shape
  100.     {
  101.         // Return area of the pentagon.
  102.         public void Area(double apothem, double length)
  103.         {
  104.             area = (5 * length * apothem) /2;
  105.         }
  106.     }
  107.     class circle : Shape
  108.     {
  109.         // Return area of the circle.
  110.         public void Area(double radius)
  111.         {
  112.             area = Math.PI * (radius * radius);
  113.         }
  114.     }
  115. }
  116.    
  117.