7.2 设计一个点类,其中包含一对坐标点数据成员、一个求两个点之间距离的友元函 数 dist 和显示坐标点的成员函数,并用数据进行测试。
2016-07-29 23:14
561 查看
#define _CRT_SECURE_NO_WARNINGS
/*
7.2 设计一个点类,其中包含一对坐标点数据成员、一个求两个点之间距离的友元函
数 dist 和显示坐标点的成员函数,并用数据进行测试。
*/
#include<iostream>
#include <math.h>
using namespace std;
class point
{
double x;
double y;
public:
point(double x1, double y1)
{
x = x1;
y = y1;
//cout <<"------000"<< x << endl;
}
void disp()
{
cout << "X坐标" << x<<endl;
cout << "Y坐标" << y<<endl;
}
double getx()
{
return x;
}
double gety()
{
return y;
}
friend double dist(point m, point n);
};
double dist(point m, point n)
{
double l = 0;
l = sqrt(((m.getx() - n.getx())*(m.getx() - n.getx()) + (m.gety() - n.gety())*(m.gety() - n.gety())));
//l = pow(((m.getx() - n.getx())*(m.getx() - n.getx()) + (m.gety() - n.gety())*(m.gety() - n.gety())), 0.5);
//cout << "---" << m.getx()<< endl;
return l;
}
void main()
{
point a(3,4);
point b(6, 8);
double d=dist(a, b);
//int d = a.getx();
cout << "距离:" << d << endl;
system("pause");
}
/*
7.2 设计一个点类,其中包含一对坐标点数据成员、一个求两个点之间距离的友元函
数 dist 和显示坐标点的成员函数,并用数据进行测试。
*/
#include<iostream>
#include <math.h>
using namespace std;
class point
{
double x;
double y;
public:
point(double x1, double y1)
{
x = x1;
y = y1;
//cout <<"------000"<< x << endl;
}
void disp()
{
cout << "X坐标" << x<<endl;
cout << "Y坐标" << y<<endl;
}
double getx()
{
return x;
}
double gety()
{
return y;
}
friend double dist(point m, point n);
};
double dist(point m, point n)
{
double l = 0;
l = sqrt(((m.getx() - n.getx())*(m.getx() - n.getx()) + (m.gety() - n.gety())*(m.gety() - n.gety())));
//l = pow(((m.getx() - n.getx())*(m.getx() - n.getx()) + (m.gety() - n.gety())*(m.gety() - n.gety())), 0.5);
//cout << "---" << m.getx()<< endl;
return l;
}
void main()
{
point a(3,4);
point b(6, 8);
double d=dist(a, b);
//int d = a.getx();
cout << "距离:" << d << endl;
system("pause");
}
相关文章推荐
- [android] 练习使用ListView(二)
- MYSQL简语---查询数据库并输出JSON
- 图论之最短路径-昂贵的聘礼
- 查找二进制缓冲区中的指定串
- UVA 1614 Hell on the Markets 【贪心+结论题】
- UVA 1614 Hell on the Markets 【贪心+结论题】
- HDU 5446 Unknown Treasure Lucas+中国剩余定理
- [2016ACM多校] HDU5764 搜索
- 自己的Android应用中调起支付宝网页
- 66.6 设计一个雇员类 employee,存储雇员的姓名、编号和生日等信息,要求该类使用 上一题设计的日期类作为成员对象。雇员类的使用如下: //定义一个雇员,其雇员号为 10,生日为 1970 年
- 进制转换
- 6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” void GetYear(); //取
- (第15讲)哈希表的开放地址法中的再哈希法
- storm常见错误
- Java工作笔记:部署Tomcat时使用jni和jna调用DLL文件的问题
- Struts2.3+Spring3.2.8+Hibernate4.1全注解配置
- 5.7 编写一个程序,其中有一个函数指针*parea,通过它分别指向计算圆的面积函数 circle 和矩形面积函数 rect 来计算给定圆的面积和矩形面积。
- Q 统计量的计算
- 首次接触Oracle
- VMware虚拟机安装步骤