using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ploymorphism
{
class Circle
{
protected double radius;
public Circle(double bj)
{
radius = bj;
}
public virtual double Area()
{
return Math.PI * radius * radius;
}
}
class Cylinder : Circle
{
double high;
public Cylinder(double r, double h)
: base(r)
{
high = h;
}
public override double Area()
{
return base.Area() * 2 + 2 * Math.PI * radius * high;
}
}
class Cone : Circle
{
double high;
public Cone(double r, double h)
: base(r)
{
high = h;
}
public override double Area()
{
return base.Area() + Math.PI * radius * Math.Sqrt(radius * radius + high * high);
}
}
class Program
{
static void Main(string[] args)
{
Circle cylinder = new Cylinder(100, 100);
Console.WriteLine("半径为100,高为100的圆柱体的表面积为{0:N2}", cylinder.Area());
Circle cone = new Cone(100, 100);
Console.WriteLine("半径为100,高为100的圆锥体的表面积为{0:N2}", cone.Area());
}
}
}