/*
*Copyright (c)2015,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:score.cpp
*作 者:战九州
*完成日期:2015年4月16日
*版 本 号: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) {}
friend double distance(CPoint &p1,CPoint &p2) ;
void input(); //以x,y 形式输入坐标点//请继续写需要的代码
};
double distance(CPoint &p1,CPoint &p2 )
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
void CPoint::input()
{
char c;
cin>>x>>c>>y;
}
int main()
{
CPoint p1,p2;
cout<<"请以“x,y”形式输入点p1的坐标:";
p1.input();
cout<<"请以“x,y”形式输入点p2的坐标:";
p2.input();
cout<<"p1到p2的距离="<<distance(p1,p2)<<endl;
return 0;
}
第五周项目四友元函数
最新推荐文章于 2024-07-18 23:31:00 发布