?? 5_6.cpp
字號:
//5_6.cpp
#include <iostream>
#include <cmath>
using namespace std;
class Point //Point類定義
{
public: //外部接口
Point(int xx=0, int yy=0) {X=xx;Y=yy;}
int GetX() {return X;}
int GetY() {return Y;}
friend float fDist(Point &a, Point &b); //友元函數聲明
private: //私有數據成員
int X,Y;
};
float fDist(Point &p1, Point &p2) //友元函數實現
{ double x=double(p1.X-p2.X); //通過對象訪問私有數據成員
double y=double(p1.Y-p2.Y);
return float(sqrt(x*x+y*y));
}
void main() //主函數
{
Point myp1(1,1),myp2(4,5); //定義Point類的對象
cout<<"The distance is:";
cout<<fDist(myp1,myp2)<<endl; //計算兩點間的距離
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -