Functions and Recursions – Geometry – Problem #6
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Two rectangles are said to overlap if there exists a common point lying inside or on the boundary of both rectangles.Assume that all rectangles have edges parallel to the x and y axes, and all rectangles lie completely within the first quadrant itself (i.e their corner point coordinates are all positive numbers). The rectangle can be represented by a pair of diagonal points (x1, y1) and (x2, y2), using an array rect[4] = {x1, y1, x2, y2}. (a) Write a C function int overlap(float [ ], float [ ]) that receives the diagonally opposite corner points of two rectangles as arguments. The function returns 1 if the rectangles overlap, otherwise 0. (b) Write a main() program that reads the values of coordinates of diagonally opposite corner points for three rectangles r1, r2 and r3 . For coordinates, consider floating point numbers as well. Hence, for the three rectangles, consider each unique pair of rectangles and print whether the pair overlaps or not. Call the function int overlap(float [ ], float [ ]) to check for each pair. For output, simply print the rectangle pair and its overlap status. [40] For example: (r1, r2) — Overlaps (r1, r3) — Does not overlap (r2, r3) — Overlaps If all the 3 pairs of rectangles overlap, then you may print (r1, r2, r3) - overalp