基类、派生类
class Program
{
public abstract class Point
{
private int x;
private int y;
public int X
{
get
{
return x;
}
set
{
x = value;
}
}
public int Y
{
get
{
return y;
}
set
{
y = value;
}
}
}
public class Line : Point
{
public double CalLength(Line pStartPoint,Line pEndPoint)
{
int dx=pStartPoint.X - pEndPoint.X;
int dy=pStartPoint.Y - pEndPoint.Y;
return Math.Round(Math.Sqrt(dx *dx+dy*dy),2);
}
}
public class Rectangle : Point
{
public double CalLength(Rectangle pLeftBottomPoint, Rectangle pRightTopPoin)
{
double dx=pRightTopPoin.X-pLeftBottomPoint.X;
double dy=pRightTopPoin.Y-pLeftBottomPoint.Y;
return Math.Round(dy*2+dx*2,2);
}
public double CalArea(Rectangle pLeftBottomPoint, Rectangle pRightTopPoin)
{
double dx = pRightTopPoin.X - pLeftBottomPoint.X;
double dy = pRightTopPoin.Y - pLeftBottomPoint.Y;
return Math.Round(dx * dy, 2);
}
}
static void Main(string[] args)
{
//创建线类
Line pStarPoint = new Line();
Line pEndPoint = new Line();
pStarPoint.X = 0;
pStarPoint.Y = 0;
pEndPoint.X = 10;
pEndPoint.Y = 10;
//输出线的长度
Console.WriteLine(pStarPoint.CalLength(pStarPoint, pEndPoint));
Rectangle pLeftBottomPoint = new Rectangle(); ////左下角点
Rectangle pRightTopPoin = new Rectangle(); ////右上角点
pLeftBottomPoint.X = 0;
pLeftBottomPoint.Y = 0;
pRightTopPoin.X = 20;
pRightTopPoin.Y = 20;
Console.WriteLine(pLeftBottomPoint.CalLength(pLeftBottomPoint, pRightTopPoin));
Console.WriteLine(pLeftBottomPoint.CalArea(pLeftBottomPoint,pRightTopPoin));
}
}
{
public abstract class Point
{
private int x;
private int y;
public int X
{
get
{
return x;
}
set
{
x = value;
}
}
public int Y
{
get
{
return y;
}
set
{
y = value;
}
}
}
public class Line : Point
{
public double CalLength(Line pStartPoint,Line pEndPoint)
{
int dx=pStartPoint.X - pEndPoint.X;
int dy=pStartPoint.Y - pEndPoint.Y;
return Math.Round(Math.Sqrt(dx *dx+dy*dy),2);
}
}
public class Rectangle : Point
{
public double CalLength(Rectangle pLeftBottomPoint, Rectangle pRightTopPoin)
{
double dx=pRightTopPoin.X-pLeftBottomPoint.X;
double dy=pRightTopPoin.Y-pLeftBottomPoint.Y;
return Math.Round(dy*2+dx*2,2);
}
public double CalArea(Rectangle pLeftBottomPoint, Rectangle pRightTopPoin)
{
double dx = pRightTopPoin.X - pLeftBottomPoint.X;
double dy = pRightTopPoin.Y - pLeftBottomPoint.Y;
return Math.Round(dx * dy, 2);
}
}
static void Main(string[] args)
{
//创建线类
Line pStarPoint = new Line();
Line pEndPoint = new Line();
pStarPoint.X = 0;
pStarPoint.Y = 0;
pEndPoint.X = 10;
pEndPoint.Y = 10;
//输出线的长度
Console.WriteLine(pStarPoint.CalLength(pStarPoint, pEndPoint));
Rectangle pLeftBottomPoint = new Rectangle(); ////左下角点
Rectangle pRightTopPoin = new Rectangle(); ////右上角点
pLeftBottomPoint.X = 0;
pLeftBottomPoint.Y = 0;
pRightTopPoin.X = 20;
pRightTopPoin.Y = 20;
Console.WriteLine(pLeftBottomPoint.CalLength(pLeftBottomPoint, pRightTopPoin));
Console.WriteLine(pLeftBottomPoint.CalArea(pLeftBottomPoint,pRightTopPoin));
}
}