Assignment #6 Solution

$30.00 $24.90


This problem is similar to the example shown on slides 21-24 of Lecture 3. Write a program “assignment-6.c” that creates and manages geometric shapes.

  1. Define and typedef a struct Point that contains two double variables x and y. An instance of Point represents a point in Cartsian space.

  2. Define and typedef a struct Circle that contains a double variable radius and a Point variable center.

  3. Define and typedef a struct Rectangle that contains a Point variable origin that is the top left corner of the rectangle, and two double variables width and height.

  4. Create a function distanceofPoints() that takes const pointers to two Point structs, and computes the distance between them. The distance between two points is the square root of the square of the x distances plus the square of the y distances for the two points. The function returns a double.

  5. Create a function intersectsCircles() that takes const pointers to two Circle structs circle1 and circle2and returns true if the two circles intersect and false otherwise. Two circles intersect if the distance between their centers is less than the sum of the two radii (if they are equal, the two circles touch but do not intersect.

  6. Create a function getBoundingBox() that takes a const pointer to a in input parameter Circle, circle and a pointer to a Rectangle result parameter boundingBox. The function sets the fields of Rectangle to the bounding box that encloses the circle. The function returns the Rectangle result parameter pointer.

  7. Create a main program that tests the intersectsCircles() function using the following cases:

    • circle1 at 0,0 radius 10, and circle2 at 21,0, radius 10: do not intersect

    • circle1 at 0,0 radius 10, and circle3 at 20, 0, radius 10: do not intersect

    • circle1 at 0,0 radius 10, and circle4 at 19,0, radius 10: intersect

  8. Also in the main program, test the getBoundingBox() function by declaring an uninitialized RectangleboundingBox and calling the getBoundingBox() function for circle1, circle2, circle3, and circle4. Print the origin, width, and height of the boundingBox for each circle.