Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- abstract class Figura
- {
- public const double PI = Math.PI;
- protected double x;
- protected double y;
- public Figura (double x, double y)
- {
- this.x = x;
- this.y = y;
- }
- public abstract double CalcularArea();
- }
- class Circulo : Figura
- {
- public Circulo(double radio)
- : base(radio, 0)
- {
- }
- public override double CalcularArea()
- {
- return PI * x * x;
- }
- }
- class Cilindro : Circulo
- {
- public Cilindro (double radio, double altura)
- : base (radio)
- {
- y = altura;
- }
- public override double CalcularArea()
- {
- return ( 2 * base.CalcularArea()) + ( 2 * PI * x * y);
- }
- }
- class PruebaFiguras
- {
- static void Main()
- {
- double radio = 3.7;
- double altura = 3.1;
- Circulo circulo = new Circulo(radio);
- Cilindro cilindro = new Cilindro(radio, altura);
- Console.WriteLine ("El área del círculo es: {0}.", circulo.CalcularArea());
- Console.WriteLine ("El área del cilindro es: {0}.", cilindro.CalcularArea());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement