设计一个类Cpoint:

2024-12-25 11:57:32
推荐回答(3个)
回答1:

#include
#include
using namespace std;
class Cpoint
{
private:
double x,y;
public:
void set(double xx,double yy)
{x=xx;y=yy;}
void show()
{
cout<<"X 和Y的坐标是:\n";
cout<}
void length()
{
double l;
l=sqrt(x*x+y*y);
cout<<"坐标到原点是距离是:\n"<}
};
void main()
{
Cpoint p;
double a,b;
cout<<"请输入x和y的坐标:\n";
cin>>a>>b;
p.set(a,b);
p.show();
p.length();
}
//经测试完美运行,望采纳!!

回答2:

class CPoint
{ public: int x, y;
double dis_to_zero(){ return sqrt(x*x + y*y); }
};
因为CPoint的x和y很常用,并且该类简单,所以大多编译器设定其访问方式为public

回答3:

1L威武!不过为啥不在类里加上get和set函数嘞?