第七周项目(1)-成员函数求两点间距离
2016-04-13 12:55
309 查看
问题及描述:
运行结果:
心得体会:
类的private成员无法直接输出,需要通过接口函数输出
/* *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; double far; public: CPoint(double,double); double get_far(CPoint &p); }; CPoint::CPoint(double xx,double yy):x(xx),y(yy){} double CPoint::get_far(CPoint &p) { far=sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)); return far; } int main() { CPoint p1(0,0),p2(1,1); cout<<p1.get_far(p2)<<endl;//无法直接输出类的成员far,需要通过函数返回值或return语句 return 0; }
运行结果:
心得体会:
类的private成员无法直接输出,需要通过接口函数输出
相关文章推荐
- spark架构及其工作机制
- POJ 2406 Power Strings
- 第5周项目4-长方柱类
- 动态规划-百度-罪犯转移
- 【BZOJ3514】Codechef MARCH14 GERALD07加强版
- 如何去除Linux文件的^M字符
- spark入门及其环境搭建
- android的Bundle
- 【转】数据库常见面试题
- 希尔排序
- android学习12——重载SurfaceView一些方法的执行顺序
- Linux终端telnet连接xxx邮箱server通过命令行实现mail发送
- Ubuntu Server设置语言为英文
- 【LeetCode-27】Remove Element
- hive数据仓库入门及其环境搭建
- Xcode 创建c++项目
- 希尔排序
- Xib的使用与File'Owner总结
- HUST 1010 The Minimum Length
- 在2016(第八届)企业级数据中心建设论坛的演讲