编程小练习
2016-04-11 12:41
435 查看
/*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:李落才
*完成日期:2016年4月11日
*
*问题描述:两点间距离之综合类
*/
#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;
}
friend void len3(CPoint &p1,CPoint &p2);//友元函数声明
double getX()
{
return x;
}
double getY()
{
return y;
}
};
class Line
{
public:
Line(CPoint xp1,CPoint xp2);
void len1();
private:
CPoint p1,p2;
double len;
};
Line::Line (CPoint xp1,CPoint xp2):p1(xp1),p2(xp2)
{
double x=p1.getX()-p2.getX();
double y=p1.getY()-p2.getY();
len=(double)sqrt(x*x+y*y);
}
void Line::len1() //调用成员函数
{
cout<<"The distance is:"<<len<<endl;
}
void len2(CPoint &p1,CPoint &p2) //调用一般函数
{
double len;
double x=p1.getX()-p2.getX();
double y=p1.getY()-p2.getY();
len=(double)sqrt(x*x+y*y);
cout<<"The distance is:"<<len<<endl;
}
void len3(CPoint &p1,CPoint &p2) //调用友元函数
{
double len;
double x=p1.x-p2.x;
double y=p1.y-p2.y;
len=static_cast<float>(sqrt(x*x+y*y));
cout<<"The distance is:"<<len<<endl;
}
int main()
{
CPoint myp1(1.0,1.0),myp2(4.0,5.0); //初始化
Line line(myp1,myp2);
line.len1(); //调用成员函数
len2(myp1,myp2); //调用一般函数
len3(myp1,myp2); //调用友元函数
return 0;
}
/*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:李落才
*完成日期:2016年4月11日
*
*问题描述:两点间距离之综合类
*/
#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;
}
friend void len3(CPoint &p1,CPoint &p2);//友元函数声明
double getX()
{
return x;
}
double getY()
{
return y;
}
};
class Line
{
public:
Line(CPoint xp1,CPoint xp2);
void len1();
private:
CPoint p1,p2;
double len;
};
Line::Line (CPoint xp1,CPoint xp2):p1(xp1),p2(xp2)
{
double x=p1.getX()-p2.getX();
double y=p1.getY()-p2.getY();
len=(double)sqrt(x*x+y*y);
}
void Line::len1() //调用成员函数
{
cout<<"The distance is:"<<len<<endl;
}
void len2(CPoint &p1,CPoint &p2) //调用一般函数
{
double len;
double x=p1.getX()-p2.getX();
double y=p1.getY()-p2.getY();
len=(double)sqrt(x*x+y*y);
cout<<"The distance is:"<<len<<endl;
}
void len3(CPoint &p1,CPoint &p2) //调用友元函数
{
double len;
double x=p1.x-p2.x;
double y=p1.y-p2.y;
len=static_cast<float>(sqrt(x*x+y*y));
cout<<"The distance is:"<<len<<endl;
}
int main()
{
CPoint myp1(1.0,1.0),myp2(4.0,5.0); //初始化
Line line(myp1,myp2);
line.len1(); //调用成员函数
len2(myp1,myp2); //调用一般函数
len3(myp1,myp2); //调用友元函数
return 0;
}
相关文章推荐
- 冒泡排序(java实现)
- Python 核心编程chap7学习笔记
- 学习Spring.Net_1
- Eclipse切换SVN用户
- 编程小练习
- 编程小练习
- 编程小练习
- FragmentPagerAdapter 动态删除的问题
- 编程小练习
- [Asp.net 开发系列之SignalR篇]专题六:使用SignalR实现消息提醒
- Android studio 类似于eclipse 中的 Ctrl+1 快捷键(quick fixes available)
- pat1001
- PHP计算一年有多少周,每周开始日期和结束日期
- Django REST framework教程二: 请求和响应
- Matlab GUI图像学习图像处理进阶
- PHP安装、配置及拓展总结
- 增加phpmyadmin导入文件上限
- SpringMVC和struts2的比较
- 开源Registry项目Harbor源代码结构解析
- 关于Class.getResource和ClassLoader.getResource的路径问题