nevermind, I figured it out.
How would I now code a function
to find rectangle r's center point;
returning point as my result????
one thing I know, is that I will have to type cast the result
because could have possible answer like (2.5, 4.5) etc.
I also I know center coordinates are based on following:
(rect.lower_right.x - rect.lower_right.y)/2 = x coordinate of center
(rect.upper_left.y - rect.upper_left.x)/2 = y-coordinate of center
Now how to incorporate all this into a function definition,
I don't know.
Any further help, would be wonderful.
Sue B.
dazed and confused
The best way to do this is to add to double types to your structure. They are part of the rectangle logic. So put these in the structure declaration and use them.
double cx; //center x co-ordinate
double cy; //center y co-ordinate
^
| UL
| _ _ _ _ _
| | |
| |_ _ _ _ _|
| LR
|
| |
______________________________
for rectangles like above
rect.upper_left.y > rect.lower_right.y
so you get the negative of the actual area
int area_of_r ( struct rectangle rect ) {
int area;
area = (rect.lower_right.x - rect.upper_left.x ) *
( rect.upper_left.y - rect.lower_right.y);
/*(rect.lower_right.y - rect.upper_left.y );*/
return area;
}