
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;
}