友元函数
2016-06-23 22:26
169 查看
/*
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年6月23日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
*/
#include <iostream>
#include<cmath>
using namespace std;
class Point
{
public:
Point(int x=0,int y=0):x(x),y(y){}
int getX(){return x;}
int getY(){return y;}
friend float dist(Point &p1,Point &p2);
private:
int x,y;
};
float dist(Point &p1,Point &p2)
{
double x=p1.x-p2.x;
double y=p1.y-p2.y;
return static_cast<float>(sqrt(x*x+y*y));
}
int main()
{
Point myp1(1,1),myp2(4,5);
cout<<"The distance is:";
cout<<dist(myp1,myp2)<<endl;
return 0;
}
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年6月23日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
*/
#include <iostream>
#include<cmath>
using namespace std;
class Point
{
public:
Point(int x=0,int y=0):x(x),y(y){}
int getX(){return x;}
int getY(){return y;}
friend float dist(Point &p1,Point &p2);
private:
int x,y;
};
float dist(Point &p1,Point &p2)
{
double x=p1.x-p2.x;
double y=p1.y-p2.y;
return static_cast<float>(sqrt(x*x+y*y));
}
int main()
{
Point myp1(1,1),myp2(4,5);
cout<<"The distance is:";
cout<<dist(myp1,myp2)<<endl;
return 0;
}
相关文章推荐
- 将文字TextView的内容斜过来,应用例如:商品促销的标签
- 记common-email发送邮件,使用qq邮箱服务器
- ADB无法找到Android设备
- 设计模式之策略模式
- nginx信息功能启用
- 约瑟夫环 Python&Swift实现
- 在你步入职业软件开发生涯那天起就该知道的五件事
- c语言学习笔记35之calloc
- iPython快捷键使用技巧简约版
- 阅读笔记09
- nginx虚拟主机别名配置
- 数组中重复次数最多的数
- 2016年学习心得
- 记自己写的第一个批处理
- RecyclerView 自适应高度 正确做法。
- 图形数据库Neo4j(1)----简介及使用
- 补码:统一加减运算
- 问题 H: 简单表达式求值
- hibernate查询
- 15.2