问题及代码:
把定义平面直角坐标系上的一个点的类CPoint作为基类,派生出描述一条直线的类Cline,再派生出一个矩形类CRect。要求成员函数能够求出两点间的距离、矩形的周长和面积等。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class CPoint
{
public double x;
public double y;
public double GetX() { return x; }
public double GetY() { return y; }
public void setPoint(int m,int n){x=m;y=n;}
}
class Cline : CPoint
{
public double Dis(CPoint P1,CPoint P2)
{
double dis;
dis = Math.Sqrt((P1.GetX() - P2.GetX()) * (P1.GetX() - P2.GetX()) + (P1.GetY() - P2.GetY()) * (P1.GetY() - P2.GetY()));
return dis;
}
}
class CRect : Cline
{
public CRect() { }
double length=0, area=0;
public double Getlength(CPoint p1,CPoint p4)
{
return length =