#include<iostream.h>
#include<iomanip.h>
#include<math.h>
const int DT=5;
template <class T>
class point	//point 类的定义
{
 public:	//外部接口
	point(T a=0, T b=0);	//构造函数
	void display(void);
	void move(T xx,T yy=0);
	T getx(void);
	T gety(void);
 private:	//私有数据
	T x;
	T y;
};
//成员函数的实现
template <class T>
 point <T>::point(T a,T b)
{
	x=a;
	y=b;
}
template <class T>
 void point <T>::display(void)
{
	cout<<"x="<<setprecision(3)<<x<<" y="<<setprecision(3)<<y<<endl;
}
template <class T>
 void point <T>::move(T xx,T yy)
{
    x+=xx;
	y+=yy;
}
template <class T>
 T point <T>::getx(void)
{
 return(x);
}
template <class T>
 T point <T>::gety(void)
{
 return(y);
}
class plane
{
 public:
	plane(float v1=1000,float x=0,float y=0);
    ~plane();
	void move(void);
	float getx(void);
 private:
    point <float> p;
	float v;
};
plane::plane(float v1,float x,float y):p(x,y)
{
     v=v1;
}    
plane::~plane()
{
   cout<<"飞机消失"<<endl;
}
void plane::move(void)
{
   float dx;
   dx=v*DT;
   p.move(dx);
   cout<<"飞机坐标:";
   p.display();
}
float plane::getx(void)
{
  return(p.getx()); 
}
class missile
{
 public:
   missile(float v1,float x,float y,float t1); 
   ~missile();
   void move(plane &a);
   int check_t(void);
 private:
   point <float> p;
   float v;
   float s;
   float t;
};
missile::missile(float v1,float t1,float x,float y):p(x,y)
{
   v=v1;
   t=t1;
}
missile::~missile()
{
 cout<<"导弹消失"<<endl;
}
void missile::move(plane &a)
{
  float s1,s2,dx,dy;
  s1=p.gety();
  s2=p.getx()-a.getx(); 
  s=sqrt(s1*s1+s2*s2);
  cout<<"导弹坐标:";
  p.display();
  dx=v*DT*s2/s;
  dy=v*DT*s1/s;
  p.move(-dx,-dy);  
}
int missile::check_t(void)
{
  int flag;
  if(s>t)
   flag=0;
  else
   flag=1;
  return(flag);
}
 int main()
{
 int i=0;
 missile m(10,5,40,100);
 plane n(5,0,0);
 do{
  n.move();
  m.move(n);
  i++;
 }while(m.check_t()==0);
 cout<<"导弹经过"<<i<<"步之后追上飞机"<<endl;
 return(0);
}