int main(int argc, char** argv, char** envp) { rectangle* r=create_rectangle(5,6); printf("r is at %p\n", r); printf("the area of the rectangle is %d\n", rectangle_area(r)); rectangle_destroy(r); rectangle* r2=(rectangle*)alloca(sizeof_rectangle()); construct_rectangle(r2, 7, 8); printf("r2 is at %p\n", r2); printf("the area of the rectangle is %d\n", rectangle_area(r2)); int i; rectangle* myrectangles=(rectangle*)malloc(100*sizeof_rectangle()); char* p=(char*)myrectangles; for(i=0;i<100;i++) { construct_rectangle((rectangle*)p, 7, 8); p+=sizeof_rectangle(); } p=(char*)myrectangles; for(i=0;i<100;i++) { rectangle_destroy((rectangle*)p); p+=sizeof_rectangle(); } return EXIT_SUCCESS; }
int main(int argc, char** argv, char** envp) { rectangle* r=(rectangle*)malloc(sizeof(rectangle)); rectangle_set_width(r,5); rectangle_set_height(r,6); printf("the area of the rectangle is %d\n", rectangle_area(r)); return 0; }
int main() { assert(EQ(20, rectangle_area(point(1, 1), point(5, 6)))); assert(point_in_rectangle(point(0, -1), point(0, -3), 3, 2)); assert(point_in_rectangle(point(2, -2), point(3, -3), -3, 2)); assert(!point_in_rectangle(point(0, 0), point(3, -1), -3, -2)); assert(point_in_rectangle(point(2, -2), point(3, -3), point(0, -1))); assert(!point_in_rectangle(point(-1, -2), point(3, -3), point(0, -1))); point p, q; assert(-1 == rectangle_intersection(point(0, 0), point(1, 1), point(2, 2), point(3, 3))); assert(0 == rectangle_intersection(point(1, 1), point(7, 7), point(5, 5), point(0, 0), &p, &q)); assert(EQP(p, point(1, 1)) && EQP(q, point(5, 5))); assert(1 == rectangle_intersection(point(1, 1), point(0, 0), point(0, 0), point(1, 10), &p, &q)); assert(EQP(p, point(0, 0)) && EQP(q, point(1, 1))); assert(2 == rectangle_intersection(point(0, 5), point(5, 7), point(1, 6), point(2, 5), &p, &q)); assert(EQP(p, point(1, 6)) && EQP(q, point(2, 5))); return 0; }
int main(int argc, char** argv, char** envp) { rectangle* r=create_rectangle(5,6); printf("the area of the rectangle is %d\n", rectangle_area(r)); rectangle_destroy(r); return 0; }