Advertisement
Fhernd

Figura.cs

Nov 13th, 2017
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. abstract class Figura
  4. {
  5.     public const double PI = Math.PI;
  6.     protected double x;
  7.     protected double y;
  8.    
  9.     public Figura (double x, double y)
  10.     {
  11.         this.x = x;
  12.         this.y = y;
  13.     }
  14.    
  15.     public abstract double CalcularArea();
  16. }
  17.  
  18. class Circulo : Figura
  19. {
  20.     public Circulo(double radio)
  21.         : base(radio, 0)
  22.     {    
  23.     }
  24.    
  25.     public override double CalcularArea()
  26.     {
  27.         return PI * x * x;
  28.     }
  29. }
  30.  
  31. class Cilindro : Circulo
  32. {
  33.     public Cilindro (double radio, double altura)
  34.         : base (radio)
  35.     {
  36.         y = altura;
  37.     }
  38.    
  39.     public override double CalcularArea()
  40.     {
  41.         return ( 2 * base.CalcularArea()) + ( 2 * PI * x * y);
  42.     }
  43. }
  44.  
  45. class PruebaFiguras
  46. {
  47.     static void Main()
  48.     {
  49.         double radio = 3.7;
  50.         double altura = 3.1;
  51.        
  52.         Circulo circulo = new Circulo(radio);
  53.         Cilindro cilindro = new Cilindro(radio, altura);
  54.        
  55.         Console.WriteLine ("El área del círculo es: {0}.", circulo.CalcularArea());
  56.         Console.WriteLine ("El área del cilindro es: {0}.", cilindro.CalcularArea());
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement