#include <iostream>
#include <math.h>

//using namespace std;

char *strdup(const char *str)
  {
   int len=strlen(str)+1;
   char *wynik=new char[len];
   memcpy(wynik,str,len);
   return wynik;
  }

class Punkt
  {
   public:
   double x,y;
   Punkt():x(0),y(0) {}
   Punkt(double x,double y):x(x),y(y) {}
   double operator-(const Punkt &P)const;
   virtual ostream &Drukuj(ostream &s)const { return s<<'('<<x<<','<<y<<')'; }
  };

double Punkt::operator-(const Punkt &P)const
  {
   double dx=P.x-x,dy=P.y-y;
   return sqrt(dx*dx+dy*dy);
  }
  
ostream &operator<<(ostream &s,const Punkt &P)
  {
   return P.Drukuj(s);
  }

class Miasto:public Punkt
  {
   char *Nazwa;
   public:
   //Miasto():Puinkt(),Nazwa(0) {}
   Miasto(const char *Nazwa):Nazwa(strdup(Nazwa)) {}
   Miasto(const Miasto &M,double x,double y):Punkt(x,y),Nazwa(strdup(M.Nazwa)) {}
   Miasto(const Miasto &M):Punkt(M),Nazwa(strdup(M.Nazwa)) {}
   ~Miasto() { delete[] Nazwa; }
   const char *nazwa()const { return Nazwa; }
   virtual ostream &Drukuj(ostream &s)const { return Punkt::Drukuj(s)<<' '<<Nazwa; }
  };

ostream &operator<<(ostream &s,const Miasto &M)
  {
   return M.Drukuj(s);
  }

int main()
  {
   Punkt P(12,5);
   Miasto M("warszawa",3,4);
   
   Punkt *T[2];
   T[0]=&M;
   T[1]=&P;
   for(int i=0;i<2;++i) cout<<*(T[i])<<endl;
   
  
   cin.get();
   return 0;
  }
