第七周项目1-一般函数
2016-04-17 12:40
295 查看
问题及代码:
运行结果:
知识点总结:一般函数不能使用类的私有成员,只能通过共有成员中的函数知道私有成员x和y的值。
学习心得:一般函数不能直接访问类的私有成员。
问题及代码:
/* *copyright (t) 2016,烟台大学计算机学院 *All rights reserved. *文件名称:test.cpp *作者:张晴晴 *完成日期:2016年4月17日 *版本号:v1.0 *问题描述:一般函数中使用类的成员。 *输入描述:无。 *程序输出:两点之间的距离。 */ #include<iostream> #include<cmath> using namespace std; class cpoint { public: cpoint(double xx=0,double yy=0):x(xx),y(yy){} double getx(){return x;} double gety(){return y;} private: double x; double y; }; void display3(cpoint&p1,cpoint&p2) { double x=p1.getx()-p2.getx(); double y=p1.gety()-p2.gety(); cout<< sqrt(x*x+y*y)<<endl; } int main() { cpoint p1(6,6); cpoint p2(4,4); display3(p1,p2); //一般函数的调用 return 0; }
运行结果:
知识点总结:一般函数不能使用类的私有成员,只能通过共有成员中的函数知道私有成员x和y的值。
学习心得:一般函数不能直接访问类的私有成员。
相关文章推荐
- 自己训练SVM分类器进行HOG行人检测
- Cocos2d-x3.x笔记目录
- volatile和synchronized的区别与联系
- localtime和gmtime函数使用
- 使用 matlab 数字图像处理(六)—— 空域滤波
- 第七周项目1-友元函数
- C#的委托
- vagrant 下安装lnmp 环境
- 用两个栈实现队列
- iOS获取通话状态
- 你不懂,仅仅有程序猿懂
- Linux的chattr与lsattr命令详解
- android应用中去掉标题栏的方法
- C#多线程中参数的传入
- 20145324 《Java程序设计》第7周学习总结
- Windows WMIC命令使用详解(附实例)
- android线程之多线程
- Java下Web MVC的领跑者:SpringMVC
- MySql 表管理常用的sql语句
- Spring MVC 入门示例讲解