OJ友元类-计算两点间距离
2015-06-28 12:23
316 查看
问题:
代码:
运行结果:
代码:
#include <iostream> #include <iomanip> #include <cmath> using namespace std; class Point; class Distance { public: float Dis(Point & p,Point & q); }; class Point { public: Point(float a,float b):x(a),y(b){} friend class Distance; private: float x; float y; }; float Distance::Dis(Point &p,Point &q) { return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y)); } int main() { float x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; Point p(x1,y1), q(x2,y2); cout<<setiosflags(ios::fixed); cout<<setprecision(2); Distance d; cout<<d.Dis(p,q)<<endl; return 0; }
运行结果:
相关文章推荐
- codeforce 310 div2 D题 Case of Fugitive
- 用代码实现图像的去噪
- 手机输入框抖动效果 和 震动效果
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第二十课:Cocos2D-X场景切换1-3
- 面试题整理:C#(二)
- Select …forupdate语句是我们经常使用手工加锁语句。
- 聊天服务器-解密陌生人(10)位置管理和获取周围一公里陌生人
- EditText 的 自动查询
- centOS 无线网卡驱动 安装 配置
- 数据结构--二进制转化为十进制的实现
- 源码分析之struts1自定义方法的使用与执行过程
- 二叉树的一系列操作
- LeetCode Jump Game
- What qualities characterize a great PhD student
- '\r'与'\n'的区别
- shell脚本:猜数字游戏
- shell脚本:猜数字游戏
- python实现搜索指定目录下文件及文件内搜索指定关键词的方法
- LeetCode Spiral Matrix
- tortoiseSVN svn+ssh