友元类——计算两点间的距离
来源:互联网 发布:windows系统是什么 编辑:程序博客网 时间:2024/05/18 01:53
问题及代码:
运行结果:
/*。*Copyright(c)2014,烟台大学计算机学院*All right reserved,*文件名:test.cpp*作者:liu_feng_zi_*完成日期:2015年6月22日*版本号:v1.0*问题描述:*输入描述:*程序输出:*/#include <iostream>#include <iomanip>#include <cmath>using namespace std;class Point{private: float x,y;public: Point():x(0),y(0){} Point (float a,float b):x(a),y(b){} friend class Distance;};class Distance{public: float Dis(Point & p,Point & q);};float Distance::Dis(Point & p,Point & q){ float dx=p.x-q.x; float dy=p.y-q.y; return sqrt(dx*dx+dy*dy);}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;}
运行结果:
0 0
- 友元类——计算两点间的距离
- hdu2001——计算两点间的距离
- 2001——计算两点间的距离
- C++刷题——1924: 计算两点间的距离
- 杭电2001——计算两点间的距离
- java实现——2001计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- List接口
- 只用getchar函数读入一个整数(算法竞赛入门经典 完整版)
- 谈谈iOS中粘性动画以及果冻效果的实现
- 第六章
- 2015062202 - CSDN手机app
- 友元类——计算两点间的距离
- Winsocket编程一般步骤-服务端编程
- 如何使用laravel搭建后台登录系统
- Collection接口
- leetcode-141-Linked List Cycle
- 分治法进行排序
- web python -- WSGI接口
- CDOJ 1059 秋实大哥与小朋友(离散化)
- 今日总结