#include <stdio.h>

/* Structures must be defined before first use */
struct Point {
  int x;
  int y;
};

/* Normally, C makes you type 'struct Point' every time you
   use the above structure.  This is extremely annoying.  The
   next statement makes it so that the name 'Point' is the  
   same as 'struct Point' */

typedef struct Point Point;

/* typedef is commonly used at the same time as the structure
   is defined.  The following example defines a structure
   'struct Rectangle', but calls it 'Rectangle'.  It looks
   weird, but you will often see this if you ever have to
   look at other people's C code.  Note: this is not needed
   in C++ */

typedef struct Rectangle {
  Point p1;
  Point p2;
} Rectangle;

/* Point Constructor.
   This function manufactures a new point and sets its
   values.  Normally, a program wouldn't know in advance
   how many points would be created.  So, you use this
   function to create a point whenever you need one */

Point *new_Point(int x, int y) {
  Point *p;
  /* Get a piece of memory to hold a point */
  p = (Point *) malloc(sizeof(Point));

  /* Set its value */
  p->x = x;
  p->y = y;

  /* Return the point */
  return p;
}

/* Destructor.
   Destroys a point created with new_Point().  This reclaims memory */

void delete_Point(Point *p) {
  free(p);
}

/* Print out a point on the screen */
void Point_print(Point *p) {
  printf("Point(%d,%d)\n", p->x, p->y);
}

/* Move a point */
void Point_move(Point *p, int dx, int dy) {
  p->x = p->x + dx;
  p->y = p->y + dy;
}

main() {
  Point *p1,*p2;

  p1 = new_Point(10,100);
  p2 = new_Point(100,200);

  Point_print(p1);

  Point_move(p1,-30,50);
  Point_print(p1);

  /* Clean up */
  delete_Point(p1);
  delete_Point(p2);
}

