#include <iostream.h>
#include <string.h>
using namespace std;

class Point {
public:
   int x_cor, y_cor;
   void move(int dx, int dy);
   // virtualがついているときとついていないときの違いを確かめる
   /* virtual */ void print(void); 
   Point() {};
   Point(int x, int y) { x_cor = x; y_cor = y; }
};

void Point::move(int dx, int dy) {
   x_cor += dx;
   y_cor += dy;
}

void Point::print() {
  cout << "(" << x_cor << ", " << y_cor << ")";
}

// ----------------------------------------------------------------------


class ColorPoint : public Point {
private:

   int color;     // 0-黒 1-赤 2-緑 3-黄 4-青 5-紫 6-水 7-白 
public:
   void print(void);
   void setColor(char* c);
   char* getColor(void);
   ColorPoint() {}
   ColorPoint(int x, int y, char* c) : Point(x, y) {
     setColor(c);
   }
};

void ColorPoint::print() {
   cout << "<font color='" << color+30 << "'>";
//   cout << "(" << x_cor << ", " << y_cor << ")";
   Point::print();
   cout << "</font>";
}

static char* cs[] = { "black", "red", "green", "yellow"
  	            , "blue", "magenta", "cyan", "white" };

void ColorPoint::setColor(char* c) {
   char i;

   for (i=0; i<8; i++) {
      if (!strcmp(c,cs[i])) {
        color = i;
	return;
      }
   }
   // 対応する文字がなかったら何もしない。
}

char* ColorPoint::getColor() {
   return cs[color];
}

// ----------------------------------------------------------------------

class DeepPoint : public Point {
private:
   int depth;
public:
   void setDepth(int);
   int getDepth(void); 
   void print(void);
   DeepPoint() {}
   DeepPoint(int x, int y, int d) : Point (x, y) {
      depth = d; 
   }
};

int DeepPoint::getDepth() {
   return depth;
}

void DeepPoint::setDepth(int d) {
   depth = d;
}

void DeepPoint::print() {
   int i;

   for (i=0; i<depth; i++) {
      cout << "(";
   }
   cout << x_cor << ", " << y_cor;
   for (i=0; i<depth; i++) {
      cout << ")";
   }
}

// ----------------------------------------------------------------------

void testPoint(Point* p) {
   p->move(10, 10);
   p->print();
}

int main() {
/*
   Point p;
   p.x_cor = 1;  p.y_cor = 2;

   ColorPoint cp;
   cp.x_cor = 3; cp.y_cor = 4; cp.setColor("blue");

   DeepPoint sp;
   sp.x_cor = 5; sp.y_cor = 6; sp.setDepth(5);

   Point* pts[3];
   pts[0]=&p; pts[1]=&cp; pts[2]=&sp;
*/

   Point* p       = new Point(1, 2);
   ColorPoint* cp = new ColorPoint(3, 4, "green");
   DeepPoint* dp  = new DeepPoint(5, 6, 5);
 
   testPoint(p);
   testPoint(cp);
   testPoint(dp);

   cout << endl;
}


#if 0
int main() {
   DeepPoint p;
   p.x_cor = 10; p.y_cor = 20; p.setDepth(5);
   p.move(1, -1);
   p.print();
   cout << endl;

/*
   ColorPoint p;

   p.x_cor = 10; p.y_cor = 20; p.setColor("blue");
   p.move(1, -1);
   p.print();
   cout << endl;
*/
/*
   Point p;

   p.x_cor = 0; p.y_cor = 0;
   p.move(1, -1);
   p.print();
   cout << endl;
*/
/*
   Point *pt;

   pt = new Point;
   pt->x_cor = 0; pt->y_cor = 0;
   pt->move(10, 20);
   pt->print();
   delete pt;
   cout << endl;
*/
}
#endif
