1条回答 默认 最新
- 南城Flipped 2021-12-08 09:02关注
#include<iostream> #include<cmath> using namespace std; class Point { float x; float y; public: Point() //显示定义一个默认构造函数 { x = 0; y = 0; } Point(float x, float y) { this->x = x; this->y = y; } float getx() { return x; } float gety() { return y; } }; class Rectangle { Point TopLeft; Point RightBottom; public: Rectangle() { TopLeft = Point(); RightBottom = Point(); } Rectangle(float tlx, float tly, float rbx, float rby) { TopLeft = Point(tlx, tly); RightBottom = Point(rbx, rby); } double Area() { return abs((TopLeft.getx() - RightBottom.getx()) * (TopLeft.gety() - RightBottom.gety())); } double Perimeter() { return (abs(TopLeft.getx() - RightBottom.getx()) * 2 + abs((TopLeft.gety() - RightBottom.gety())* 2)); } }; int main() { float tlx, tly, rbx, rby; Rectangle rectangle; cout << "请输入左上点x坐标:"; cin >> tlx; cout << "请输入左上点y坐标:"; cin >> tly; cout << "请输入右上点x坐标:"; cin >> rbx; cout << "请输入右上点y坐标:"; cin >> rby; rectangle = Rectangle(tlx, tly, rbx, rby); cout << "周长:" << rectangle.Perimeter() << "面积:" << rectangle.Area() << endl; }
没细测
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 c#转安卓 java html
- ¥15 os.listdir文件路径找不到
- ¥15 使用gojs3.0,如何在nodeDataArray设置好text的位置,再go.TextBlock alignment中进行相应的改变
- ¥15 psfusion图像融合指标很低
- ¥15 银河麒麟linux系统如何修改/etc/hosts权限为777
- ¥50 医院HIS系统代码、逻辑学习
- ¥30 docker离线安装mysql报错,如何解决?
- ¥15 构建工单的总账影响在哪里查询或修改
- ¥15 三个简单项目写完之后有重赏之后联系我
- ¥15 python报内存不能read错误