C++程序填空

来源:百度知道 编辑:UC知道 时间:2024/06/09 04:37:10
#include <iostream.h>
#include <cmath.h>
class TPoint
{
private:
double x,y;
public:
TPoint(double a,double b)
{
___x=a_______;
__________;
cout<<”点:(“<<x<<”,”<<y<<”)”<<endl;
}
friend double distance(TPoint &a,TPoint &b) //求两点间的距离
{
return ________________________________;
}
};
void main( )
{ TPoint p1(2,1),p2(5,5);
cout<<”上述两点之间的距离”<< _____________<<endl; }

#include <iostream.h>
#include <math.h>

class TPoint
{
private:
double x,y;
public:
TPoint(double a,double b)
{
this->x = a;
this->y = b;
cout<<"点:("<<x<<","<<y<<")"<<endl;
}
friend double distance(TPoint &a,TPoint &b) //求两点间的距离
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
};
void main( )
{
TPoint p1(2,1),p2(5,5);
cout<<"上述两点之间的距离"<< distance(p1,p2) <<endl;
}

一楼的少侠已经回答正确了,我在这里改一下,希望大家使用C++标准来编程。this指针在这里可以省。这里还是用到了C的.h文件。对于主函数来说,在C++标准中是明确注明不可以用 void 的,只能用int 并且有返回值 0。void 是C的风格,在一些C++程序中是不可以用void的。希望大家都用C++标准编程有利于C++的发展和相互交流。
#include <iostream.h>
#include <math.h>

class TPoint
{
private:
double x,y;
public:
TPoint(double a,double b)