64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
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, float)
{
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;
char response;
cin >> response;
return 0;
}
void Point::setPoint(float a, float b)
{
x = a;
y = b;
}
#include <iostream.h>
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;
char response;
cin >> response;
return 0;
}