您的位置:首页 > 其它

第七周项目3-成员函数、友元函数和一般函数区别

2014-04-07 22:02 260 查看
/*
*Corpyright (c)2013,烟台大学计算机学院
*All right reseved.
*作者:z张梦佳
*完成日期:2014年4月7日
*版本号:v1.0
*输入描述:
*问题描述:复制类!
*程序输出:
*问题分析:
*算法设计:
*/
#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
double x;  // 横坐标
double y;  // 纵坐标
public:
CPoint(double xx=0,double yy=0):x(xx),y(yy){}
void input();
friend double getput(CPoint &p,CPoint &s);
double num(CPoint &p);
double get_x();
double get_y();
};
double CPoint::get_x()
{
return x;
}
double CPoint::get_y()
{
return y;
}
void CPoint::input()
{
double a,b;
cout<<"请输入一个点的坐标:"<<endl;
cin>>a>>b;
x=a;
y=b;
}
double CPoint::num(CPoint &p)
{
double s;
s=sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
return s;
}
double getput(CPoint &p,CPoint &s)
{

return sqrt((p.x-s.x)*(p.x-s.y)+(p.y-s.y)*(p.y-s.y));
}
double mmmm(double ,double ,double ,double);
int main()
{
CPoint a,b;
a.input();
b.input();
cout<<"两点的距离为:"<<a.num(b)<<endl;
cout<<"两点的距离为:"<<getput(a,b)<<endl;
cout<<"两点的距离为:"<<mmmm(a.get_x(),a.get_y(),b.get_x(),b.get_y())<<endl;

return 0;
}
double mmmm(double a,double b,double c,double d)
{
double s;
s=sqrt((a-c)*(a-c)+(b-d)*(b-d));
return s;
}




感悟

好难,坐了好久。也做了好久//
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐