第七周项目(1)-普通函数求两点间距离
2016-04-13 13:24
176 查看
问题及代码:
运行结果:
![](http://img.blog.csdn.net/20160413132617152)
心得体会:
普通函数用到类中成员的时候声明一定要在类之后
/* *copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称:hellow.cpp *作者:田甜 *完成日期:2016年4月13日 *版本号:v1.0 *问题描述:用普通函数求两点间的距离 *输入描述://// *程序输出:按要求处理后输出 */ #include <iostream> #include <cmath> using namespace std; class CPoint { private: double x; double y; public: CPoint(double,double); double get_x(); double get_y(); }; double get_far(CPoint &p1,CPoint &p2);//get_char为普通函数,声明要在类之后 CPoint::CPoint(double xx,double yy):x(xx),y(yy){} double CPoint::get_x() { return x; } double CPoint::get_y() { return y; } double get_far(CPoint &p1,CPoint &p2) { double far=sqrt((p1.get_x()-p2.get_x())*(p1.get_x()-p2.get_x())+(p1.get_y()-p2.get_y())*(p1.get_y()-p2.get_y())); return far; } int main() { CPoint p1(0,0),p2(1,1); cout<<get_far(p1,p2)<<endl; return 0; }
运行结果:
心得体会:
普通函数用到类中成员的时候声明一定要在类之后
相关文章推荐
- Eclipse 下maven 笔记
- ubuntu系统的grub配置
- STL中二分查找 lower_bound()
- 关于java中文件下载中文乱码的事
- MyBatis异常 Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException:
- Hibernate 之 cascade 和 inverse
- Spark如何使用Akka实现进程、节点通信的简明介绍
- Podfile升级后的影响
- Best Time to Buy and Sell Stock
- Split函数,正则表达式与空字符串
- JSP大学实用教程(第2版)代码一
- 接受前台数据
- EXT.NET MVC 5 工作随笔02 传参时如果参数在当前页面获取不到时,用?解决
- C++第3次上机作业
- 规则引擎笔记
- Android 如何动态设置View参数,LayoutParams.addRules详解,TypedValue.applyDimension的使用
- BX9054: 各浏览器对 document.execCommand 方法的首参数可选值范围存在差异
- 免费的编程中文书籍索引
- Windows系统的mstsc版本升级
- crash caused by static variable