把定义平面直角坐标系上的一个点的类CPoint作为基类,派生出描述一条直线的类Cline,再派生出一个矩形类CRect。
代码如下:
using System;
namespace Program0
{
class CPoint
{
public double x { get; set; }
public double y { get; set; }
public CPoint() { }
public CPoint(double x, double y)
{
this.x = x;
this.y = y;
}
}
class CLine : CPoint
{
public CPoint EPoint{get;set;}
public double x2{get{return EPoint.x;}set{EPoint.x=value;}}
public double y2{get{return EPoint.y;}set{EPoint.y=value;}}
public CLine()
{
EPoint=new CPoint();
}
public CLine(CPoint p1,CPoint p2)
{
base.x=p1.x;
base.y=p1.y;
EPoint=p2;
}
public double LineLength{
get{
return Math.Sqrt((x2-x)*(x2-x)+(y2-y)*(y2-y));