#include <stdio.h>

struct point
{
  int x;
  int y;
};

typedef struct point POINT;

struct rectangle
{
	struct point top_left;
	struct point bottom_right;
};

typedef struct rectangle RECTANGLE;

int computeArea(RECTANGLE *);

int main(void)
{
  struct rectangle rectangle1 = {{2, 5}, {7, 1}};
  struct point point1;
  point1.x = 3;
  point1.y = 12;
  POINT point2 = {10, 4};
  RECTANGLE rectangle2;
  rectangle2.top_left = point1;
  rectangle2.bottom_right = point2;

  int area1 = computeArea(&rectangle1);
  printf("The area of rectangle1 is %d\n", area1);

  printf("The area of rectangle2 is %d\n", computeArea(&rectangle2));

  return 0;
}

int computeArea(RECTANGLE *pr)
{
  int width = pr->bottom_right.x - pr->top_left.x;
  int height = pr->top_left.y - pr->bottom_right.y;

  /* The commented out lines below would be equivalent ot the lines above.
   * The arrow operator "->" is typically used when accessing members through
   * a poiner to a structure. It combines indirection and the dot operator.
   */

  //int width = (*pr).bottom_right.x - (*pr).top_left.x;
  //int height =(*pr).top_left.y - (*pr).bottom_right.y;

  return width*height;
}
