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