Poppy796 2021-11-06 17:20 采纳率: 75%
浏览 96
已结题

对这个题目是一头雾水啊。

1、设计点类 Point,能够表示平面当中的任意点
(1)数据成员包括两点坐标(x,y),成员函数包括构造函数、析构函数、复制构造函数;
(2)包括求点的坐标的公有接口函数,打印点坐标的成员函数,并在主函数中调用。
(3)在主函数中实例化出两个点a(0,0),b(6,8),求出两点间的距离。

  • 写回答

1条回答 默认 最新

  • 冷0_O 2021-11-06 17:54
    关注

    设计代码已给出,望采纳!

    class Point
    {
        public:
            Point(double x=0,double y=0):x(x),y(y){}
            ~Point(){}
            Point(const Point & po){ //拷贝构造(复制构造)
                this->x = po.x;
                this->y = po.y;
            }
            void modify_coordinate(double modx,double mody){ //修改坐标
                this->x = modx;
                this->y = mody;
            }
            void printf_coordinate(){ //打印坐标
                cout << "点坐标为:" << "(" << this->x << "," << this->y << ")" << endl;
            }
            void coordinate_distance(Point mp){ //求两点之间的距离
                double xd = (this->x - mp.x) * (this->x - mp.x);
                double yd = (this->y - mp.y) * (this->y - mp.y);
                double dis = pow((xd + yd),0.5); //#include <math.h>
                cout << "两点距离为:" << dis << endl;
            }
        private:
            double x;
            double y;
    };
    
    int main()
    {
        Point p{3,4};
        Point p2 = p;
        p2.modify_coordinate(6,6);
        p.coordinate_distance(p2);
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月17日
  • 已采纳回答 11月9日
  • 创建了问题 11月6日

悬赏问题

  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误