第七周项目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; }
感悟
好难,坐了好久。也做了好久//
相关文章推荐
- 第七周 项目1-成员函数、友元函数和一般函数有区别(1)
- 第七周项目1-成员函数、友元函数和一般函数有区别
- 第七周项目一-成员函数、友元函数和一般函数有区别
- 第七周 项目二:成员函数、友元函数、一般函数之区别(初体验)
- 第七周项目一 成员函数,友元函数和一般函数的区别
- 第七周【项目1-成员函数、友元函数和一般函数有区别】
- 第七周项目三成员函数,友元函数以及一般函数的区别
- 第七周项目一友元函数、成员函数和一般函数有区别2
- 第七周项目1-成员函数、友元函数和一般函数有区别(1)
- 第七周项目1-成员函数、友元函数和一般函数的区别
- 第七周项目:成员函数、友元函数和一般函数有区别
- 第七周上机任务项目2-成员函数、友元函数和一般函数的区别
- 第七周 项目二:成员函数、友元函数、一般函数之区别(实现三个版本的求两点间距离)
- 第七周 项目一 (1)成员函数、友元函数和一般函数有区别
- 第七周上机实践项目 项目1-成员函数,友元函数,和一般函数的区别(2)
- 第七周项目1-成员函数、友元函数和一般函数有区别
- 第七周项目一-成员函数、友元函数和一般函数有区别(1)
- 第七周 项目1-成员函数、友元函数和一般函数有区别(1)友元
- 第七周实践项目1-成员函数、友元函数和一般函数有区别
- 第七周项目3-成员函数、友元函数和一般函数的区别