友元函数
2016-04-17 13:10
288 查看
#include <iostream> #include<cmath> using namespace std; class Cpoint { private: double x; double y; public: Cpoint(double xx=0,double yy=0):x(xx),y(yy){} void setx(double xx); void sety(double yy); double putx(); double puty(); friend void showCpoint(Cpoint &a,Cpoint &b); }; void Cpoint::setx(double xx) { x=xx; } void Cpoint::sety(double yy) { y=yy; } double Cpoint::putx() { return x; } double Cpoint::puty() { return y; } void showCpoint(Cpoint &a,Cpoint &b) { double x=a.x-b.x; double y=a.y-b.y; cout<<sqrt(x*x+y*y)<<endl; } void show(Cpoint a,Cpoint b) { double x=a.putx()-b.putx(); double y=a.puty()-b.puty(); cout<<sqrt(x*x+y*y)<<endl; } int main() { Cpoint a(3,3),b(1,1); show(a,b); showCpoint(a,b); return 0; }
相关文章推荐
- @property和@synthesize
- mysql 5.6.14主从复制(也称mysql AB复制)环境配置方法
- HDU-1017
- zabbix
- java正则表达式之java小爬虫
- 错误解决-----java was started but returned exit code=13
- 静态数据成员应用
- rs485引脚定义
- 编译第一个opencv测试程序
- numeric(x+y,y)的长度与位数
- JS原型详解
- iOS UIScrollView和 cell加载子视图偏移64问题
- 不动点
- 汉字转拼音(域名)
- 分数类的雏形
- eclipse安装Spring插件后无法使用maven
- PHP--each与list的用法
- 拍摄照片和视频
- Eclipse使用Maven创建Web时错误:Could not resolve archetype
- 带武器的游戏角色