64,691
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
class point
{public:
point(float x=0,float y=0);
void setPoint(float,float);
float getX() const {return x;}
float getY() const {return y;}
friend ostream & operator<<(ostream &,const point &);
protected:
float x,y;
};
point::point(float a,float b)
{x=a;y=b;}
point::void setPoint(float a,float b)
{x=a;y=b;}
point::ostream & operator<<(ostream &output,const point &p)
{output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;}
int main()
{Point p(3.5,6.4);
cout<<"x="<<p.getX()<<",y="<<p.getY()<<endl;
p.setPoint(8.5,6.8);
cout<<"p(new):"<<p<<endl;
}
#include <iostream>
using namespace std;
class point
{public:
point(float x=0,float y=0);
void setPoint(float,float);
float getX() const {return x;}
float getY() const {return y;}
friend ostream & operator<<(ostream &,const point &);
protected:
float x,y;
};
point::point(float a,float b)
{x=a;y=b;}
void point::setPoint(float a,float b)
{x=a;y=b;}
ostream & operator<<(ostream &output,const point &p)
{output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;}
int main()
{point p(3.5,6.4);
cout<<"x="<<p.getX()<<",y="<<p.getY()<<endl;
p.setPoint(8.5,6.8);
cout<<"p(new):"<<p<<endl;
}