C语言习题。。大哥们帮帮忙!!!

来源:百度知道 编辑:UC知道 时间:2024/06/21 23:39:39
In computer graphics we use the concept of a ``bounding box''. A bounding box is the smallest rectangle enclosing a picture.

For simple graphics components, like a circle or a rectangle, the bounding box can be determined easily. Given a circle with centre (X,Y) and radius R, the bounding box has a lower left coordinate of (X-R,Y-R) and an upper right coordinate of (X+R,Y+R). If we want to know what the bounding box of a picture of two components is, then we can combine the bounding boxes of the two components as is shown in the figure below:

This is the way that we can establish the bounding box of Mickey Mouse. We take the bounding boxes of two components (say the left ear and left eye), and combine them. Then we combine that bounding box with the bounding box of the head, then with the right eye and finally the right ear:

In this coursework you will define data types to hold circles and bounding boxes, and functions to manipulate those typ

/* 第一题 */
  #include <stdio.h>

  typedef struct
  {
  int cx;
  int cy;
  int r;
  } Circle;

  typedef struct
  {
  int l;
  int b;
  int r;
  int t;
  } Box;

  void MakeCircle(int x, int y, int r, Circle *cir)
  {
  cir->cx = x;
  cir->cy = y;
  cir->r = r;
  }

  void MakeBox(Circle *cir, Box *box)
  {
  box->l = cir->cx - cir->r;
  box->b = cir->cy - cir->r;
  box->r = cir->cx + cir->r;
  box->t = cir->cy + cir->r;
  }

  void PrintBox(Box *box)
  {
  printf("(%d,%d) (%d,%d)\n", box->l, box->b, box->r, box->t);
  }

  int main()
  {
  Circle cir;
  Box box;
  void MakeCircle(int, int, int, Circle *);
  void MakeBox(Circle *, Box *);
  void PrintBox(Box *);

  MakeCircle(1, 2,