您的位置:首页 > 其它

第6周项目4-成员函数、友元函数和一般函数有区别 (一般函数)

2015-04-19 21:55 260 查看
/*
* Copyright (c) 2015, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作    者:梁璨
* 完成日期:2015年 4 月 19 日
* 版 本 号:v1.0
*
* 问题描述: 。
* 输入描述:NULL;
* 程序输出:按要求输出。


#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
double x;
double y;
public:
void input();
void output();
double getX();
double getY();
};

double Distance1(CPoint &p1,CPoint &p2)
{
return sqrt((p1.getX()-p2.getX())*(p1.getX()-p2.getX())+((p1.getY()-p2.getY())*(p1.getY()-p2.getY())));
}

double CPoint::getX()
{
return x;
}

double CPoint::getY()
{
return y;
}
void CPoint::input()
{
char c1,c2,c3;
cin>>c1>>x>>c2>>y>>c3;
}
void CPoint::output()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}

int main()
{
CPoint p1,p2;
cout<<"请输入x,y的坐标(以(x,y)的格式:"<<endl;
p1.input();
cout<<"请输入x,y的坐标(以(x,y)的格式:"<<endl;
p2.input();
cout<<"p1到p2的距离="<<Distance1(p1,p2)<<endl;
return 0;
}


运行结果:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐