c++相关的面向对象编程

img


c++相关的面向对象编程,只能使用c++,不能用c.语言,不知道为什么我自己写的总是有错误

你写的代码发出来看看,帮你调试一下。


#include <iostream>
#include<math.h>
using namespace std;
class MyPoint 
{  
   private:
   double x;
   double y;  
   public:
        MyPoint()
    {
    x=0;
    y=0;
    }
     MyPoint(double a,double b)
     {
       x=x;
       y=y;     
     }
    double get_x()
    {
      return x;    
    }
      void set_x(double a)
      {
        x=a;      
      }
       void set_y(double a)
      {
        y=a;      
      }
        double get_y()
    {
      return y;    
    }    
    double distance(MyPoint a)
    {
       double b;
       b=(x-a.get_x())*(x-a.get_x())+(y-a.get_y())*(y-a.get_y());
       b=sqrt(b);
       return b;    
    }
};
int main()
{  

Point a;
Point b(10,30.5);
double c;
    c=a.distance(b);
    cout<<"***********Extend MyPoint**********"<<endl;
    cout<<c;
    cout<<endl;
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632