?? c12-1-1(vc).cpp
字號:
#include <iostream.h>
//using namespace std;
//聲明類Point
class Point
{public:
Point(float=0,float=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類的成員函數(shù)
//Point的構造函數(shù)
Point::Point(float a,float b)
{x=a;y=b;}
//設置x和y的坐標值
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;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -