定义并实现一个矩形类Rectangle,其属性为矩形的左下角与右上角两个点的坐标,能设置左下角和右上角两个点的位置,能根据左下角与右上角两个点的坐标计算矩形的长、宽、周长和面积。要求用类的组合来实现(矩形的左下角与右上角两个点是Point类的对象),并要求给类定义构造函数(包括默认的构造函数、带参数的构造函数和拷贝构造函数)、析构函数。
1条回答 默认 最新
铃儿~响叮当 2024-06-07 17:00关注class Rectangle { public Point LeftBottom { get; set; } public Point RightTop { get; set; } public Rectangle() { } public Rectangle(Point leftBottom, Point rightTop) { LeftBottom = leftBottom; RightTop = rightTop; } public Rectangle(Rectangle r) { LeftBottom = r.LeftBottom; RightTop = r.RightTop; } ~Rectangle() { } public double GetWidth() { return RightTop.X - LeftBottom.X; } public double GetHeight() { return LeftBottom.Y - LeftBottom.Y; } public double GetPerimeter() { return 2 * (GetWidth() + GetHeight()); } public double GetArea() { return GetWidth() * GetHeight(); } }解决 无用评论 打赏 举报