homework problem someone plz solve..fun with geometry

closed account (oyA74iN6)
A rectangle is represented with two coordinates.The first coordinate (a,b) represents the top-left point and the second one (c,d) represents the bottom-right point of the rectangle. Likewise, a circle is represented with a coordinate (x,y) which tells the centre and the radius r.

Your task is to implement a base class called shape and derive the classes rectangle and circle from shape. As part of design, shape class should have area as member function which is required to be overridden in the derived classes (Rectangle and circle).

Also, the following operations need to be performed on the given geometric shapes.

1)Given two rectangles defined with coordinates (a1,b1),(c1,d1) and (a2,b2),(c2,d2) , find the intersection of the rectangles (if possible). Intersection operation should be overloaded using operator ’+’.All the sides of the rectangles are parallel to one of the axes.

If there is a rectangular intersection, print the coordinates (top-left and bottom-right points of the rectangle) along with the area of the intersected rectangle.
If intersection of two rectangles is at an edge (i.e, straight line as intersection), print the 2 endpoints of the intersecting line and area as 0.
If two rectangles are touching at only one point, print the coordinate of the point and area as 0.
If there is no intersection, print "-1".

2)Given two circles defined with centres and radii as (a1,b1),r1 and (a2,b2),r2 respectively, find the intersection of the circles (if possible). Intersection operation should be overloaded using operator ’+’.

If the circles intersect at two points (partially overlapping), print both the intersection points.(Order of the output should be point of intersection at the bottom followed by point of intersection at the top.)
If there is an intersection at only one point, print the single point of intersection.
If there is no intersection, print "-1".
If they are completely overlapping or one circle is completely inside the other, print "0"

Also, print the area of the two given circles at the end

Note: The line joining the centres of the circles is parallel to x-axis.π value should be fixed as 3.14 for finding circle area and the results should be correct upto 2 decimal places. For example:

if the area is 3 then print 3.00
if it is 3.2, print 3.20
if it is 3.799 print 3.79 (truncated)

Input Format

N

shape type - R(rectangle) a1 b1 c1 d1

shape type - C(circle) a1 b1 r1 a2 b2 r2

. .

Constraints
1)1≤N≤10
2)INTEGERMIN≤(a,b)≤INTEGERMAX
3)1≤radius≤INTEGERMAX
4)N - No. of Queries (operations)
5)(a,b) - x,y coordinates
N - No. of Queries (operations)
(a,b) - x,y coordinates

Output Format

x1 y1 w1 z1 area

a1 b1 c1 d1 area1 area2

Note: Can vary depending on the conditions mentioned earlier

Sample Input

2
R 8 8 14 4 6 10 10 6
C 3 3 2 6 3 1

Sample Output

8 8 10 6 4
5 3 12.56 3.14

Explanation

Rectangles intersecting at two points case; Print its top-left, right-bottom and the intersecting area
Circle intersecting at single point case; Print the intersecting point and areas of the given two circles.

Last edited on
Your task is to implement a base class called shape


Start there. Create an empty class called shape.
closed account (oyA74iN6)
can i get the complete code... i have to submit my assignment
i have to submit my assignment

It's your assignment which means that you need to write the code so that you can submit it.
Figuring the intersection of two rectangles can be a pain. Here's an easy way to do it. This assumes that x increases to the right and y increases up.

If the rectangles intersect then:
The left edge of the intersection is the MAXIMUM of the left edges of the inputs.
The right edge of the intersection is the MINIMUM of the right edges of the inputs.
Similarly, the top edge is the MINIMUM of the top edges of the inputs and the bottom edge in the MAXIMUM of the bottom edges.

What if the rectangles don't intersect? Just run the algorithm above and then check to see if the left edge of the "intersection" is indeed less than the right edge. Also check if the top is indeed greater than the bottom. To convince yourself that this works, notice that if the rectangles don't intersect then one must be above the other or to the right. In that case, the algorithm will result in a invalid rectangle (left>right or bottom>top).
Topic archived. No new replies allowed.