回复 29楼 闲出屁
真是远在天边近在眼前啊,谢了。收藏先。不过里面没有对程序代码的流程解说,我还很初级哪。

[ 本帖最后由 有容就大 于 2012-2-14 17:25 编辑 ]

梅尚程荀
马谭杨奚

程序代码: abstract class Shape
{
public abstract string ShapeName();
public abstract double Area();
}
class Triangle : Shape
{
public Triangle(double bottom_width, double hight)
{
a = bottom_width;
b = hight;
}
public override string ShapeName()
{
return "Triangle";
}
public override double Area()
{
return a * b / 2;
}
private double a;
private double b;
}
class Rectangle : Shape
{
public Rectangle(double width, double hight)
{
a = width;
b = hight;
}
public override string ShapeName()
{
return "Rectangle";
}
public override double Area()
{
return a * b;
}
private double a;
private double b;
}
class Circle : Shape
{
public Circle(double radius)
{
r = radius;
}
public override string ShapeName()
{
return "Circle";
}
public override double Area()
{
return r * r * Math.PI;
}
private double r;
}
class Program
{
static void Main(string[] args)
{
Shape[] test = new Shape[] { new Triangle(3, 2), new Rectangle(4, 5), new Circle(6) };
foreach(Shape s in test)
Console.WriteLine("The shape is {0}, and it's area are {1}", s.ShapeName(), s.Area());
}
}
