第七周【项目1-成员函数、友元函数和一般函数有区别】
2016-04-14 09:08
381 查看
/* *Copyright (c)2016,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:张珩瑞 *完成日期:2016年4月14日 *版 本 号: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) {} double distance1(CPoint &); //参数用const CPoint &更佳 friend double distance2(CPoint &, CPoint &) ; double getX() { return x; } double getY() { return y; } }; double distance3(CPoint &,CPoint &) ; double CPoint::distance1(CPoint &p) { double dx=(x-p.x), dy=y-p.y; return sqrt(dx*dx+dy*dy); } double distance2(CPoint &p1,CPoint &p2) { double dx=(p1.x-p2.x), dy=p1.y-p2.y; return sqrt(dx*dx+dy*dy); } double distance3(CPoint &p1,CPoint &p2) { double dx=(p1.getX()-p2.getX()), dy=p1.getY()-p2.getY(); return sqrt(dx*dx+dy*dy); } int main() { CPoint p1(10,13), p2(-5,6); cout<<"1. "<<p1.distance1(p2)<<endl; cout<<"2. "<<distance2(p1,p2)<<endl; cout<<"3. "<<distance3(p1,p2)<<endl; return 0; }
相关文章推荐
- Show me the code之Python练习册 Q1~3 优惠券
- 安卓四种启动模式
- Java web过滤器验证登录(避免未经登录进入主页)
- 了解点OpenAI及深度学习研究前沿
- algrothm_String s = "Hello";s = s + " world!"(内容?)
- 老逗的gcd 莫比乌斯反演
- clearfix
- 标志位简介
- 【iCore3 双核心板_FPGA】例程十三:FSMC总线通信实验——复用地址模式
- SSL常用专业缩略语汇总
- 第七周上机时间项目——项目1-求两点距离
- BZOJ 4013: [HNOI2015]实验比较
- Eclipse下NDK开发
- 百度权力调整:以Google为师,向华尔街示好
- svn : Item is out of date 解决办法
- 第6周项目2-带武器的游戏角色
- 百度步随谷歌,重组业务架构,深意何在?
- 1022. Digital Library (30)
- 深度学习研究理解6:OverFeat:Integrated Recognition, Localization and Detection using Convolutional Networks
- SGU 104 Little shop of flowers(dp)