I need some help with this programming project I am creating. The first two things I had to do I got just fine. The first two things were to compute the area of r and to compute the center of r, returning it as a point value. The next two thing I am having trouble with. Here's what I need help with:
1) Move r by x units in the x direction and y units in the y direction, returning the modified version of r. (x and y are additional arguments to the function.)
2) Determine whether a point p lies within r, returning TRUE or FALSE. (p is an additional argument of type struct point.)
I think I may have did the wrong thing for the second objective. I'm not sure. The complete direction was "compute the center of r, returning it as a point value." I don't think I used the point value and if anyone has any suggestions, please help. Here is the code I already have.
Code:#include <stdio.h> struct point { int x, y;}; struct rectangle { struct point upper_left, lower_right;} r; int area_of_r(struct rectangle rect); float center_of_rx(struct rectangle rect); float center_of_ry(struct rectangle rect); int main() { printf( "Input upper left corner of r : " ); scanf( "%d %d", &r.upper_left.x, &r.upper_left.y ); printf( "Input lower right corner of r : " ); scanf( "%d %d", &r.lower_right.x, &r.lower_right.y ); printf( "Area of r is %d\n", area_of_r(r) ); printf( "The center of r is ( %.2f, %.2f )\n", center_of_rx(r), center_of_ry(r)); return 0; } int area_of_r ( struct rectangle rect ) { int area=0; area = (rect.lower_right.x - rect.upper_left.x ) * ( rect.upper_left.y - rect.lower_right.y); return area; } float center_of_rx(struct rectangle rect) { float center=0; center = (rect.lower_right.x - rect.lower_right.y)/2; return center; } float center_of_ry(struct rectangle rect) { float center=0; center = (rect.upper_left.y - rect.upper_left.x)/2; return center; }



LinkBack URL
About LinkBacks


