using System;
using System.Drawing;
using _05_Base;
namespace _05_03
{
public class Class_05_03
{
public static void PrintArea(Shape shape)
{ //这个应该是根据传入的一个Shape类的对象 打印出对象shape的面积
Console.WriteLine("Area of {0} is : {1}", shape.Name, shape.Area);
}
public static void Main(String[] args)
{
Point p = new Point(0, 0); //初始化一个Point对象p和坐标(0,0)
_05_Base.Rectangle r = new _05_Base.Rectangle(); //初始化一个Rectangle 图形,定义名字,长和宽
r.Name = "Rectangle r";
r.Width = 10;
r.Height = 20;
Square s = new Square(); //初始化一个 Square 图形,定义名字和side
s.Name = "Square s";
s.Side = 15;
Ellipse e = new Ellipse(); //初始化一个 Ellipse 图形,定义名字,SemiMajorAxis 和SemiMinorAxi
e.Name = "Ellipse e";
e.SemiMajorAxis = 10;
e.SemiMinorAxis = 5;
Circle c = new Circle(); //初始化一个 Circle 图形,定义半径
c.Name = "Circle c";
c.Radius = 6;
Triangle t = new Triangle(); //初始化一个 Triangle 图形,定义名字,和两个点 的坐标
t.Name = "Triangle t";
t.Point1 = new Point(3, 3);
t.Point2 = new Point(3, 0);
Shape[] shapes = new Shape[5]; //定义一个基类Shape的数组,把刚初始化的几个派生类的对象放到数组里
shapes[0] = r;
shapes[1] = s;
shapes[2] = e;
shapes[3] = c;
shapes[4] = t;
foreach(Shape shape in shapes) //遍历Shape数组,打印出面积
{
shape.Position = p;
PrintArea(shape);
}
}
}
}
应该就这么多了吧,还有什么问题一起交流!
|