c++相关的面向对象编程,只能使用c++,不能用c.语言,不知道为什么我自己写的总是有错误
3条回答 默认 最新
- CSDN专家-sinJack 2022-11-10 09:12关注
你写的代码发出来看看,帮你调试一下。
#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; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录