str method(desc) (Shape self);
void method(rename) (Shape self, str name);
void method(reset) (Shape self, int x1, int y1, int x2, int y2, int x3, int y3);
- int method(area) (Shape self);
+ float method(area) (Shape self);
int count;
};
str descTri(Shape community)
{
- return "";
+ I_am(Tri);
+
+ return self->name;
}
str descRect(Shape community)
{
- return "";
+ I_am(Rect);
+
+ return self->desc;
}
str descCirc(Shape community)
{
- return "";
+ I_am(Circ);
+
+ return self->comment;
}
-int calcAreaTri(Shape community)
+float calcAreaTri(Shape community)
{
+ I_am(Tri);
+
return 0;
}
-int calcAreaRect(Shape community)
+float calcAreaRect(Shape community)
{
- return 0;
+ I_am(Rect);
+
+ return (self->x2-self->x1)*(self->y2-self->y1);
}
-int calcAreaCirc(Shape community)
+float calcAreaCirc(Shape community)
{
- return 0;
+ I_am(Circ);
+
+ return 3.14159*self->r*self->r;
}
void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3)
append(one, all);
one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Circ, circles, 10, 0, 5);
+ one->object = get_obj_as(Shape, Circ, circles, 0, 10, 1);
append(one, all);
printf("We have created %d triangles, %d rectangles and %d circles:\n",
for_each(one, all)
{
_(draw, one->object);
- printf("Area of this %s is %d (square pixels).\n", _(desc, one->object), _(area, one->object));
+ printf("Area of this %s is %f (square pixels).\n", _(desc, one->object), _(area, one->object));
printf("We have created %d instances of this type of object.\n", interface_of(one->object)->count);
if(interface_of(one->object) == rectangles)