oop_in_c/main.c

49 lines
1.2 KiB
C
Raw Normal View History

2012-04-30 18:59:30 +04:00
#include <stdio.h>
#include <stdlib.h>
#include "ColoredSquare.h"
int main (int argc, char *argv[])
{
2012-05-01 00:55:56 +04:00
unsigned long i = 0;
2012-04-30 19:31:40 +04:00
Figure *fig[3];
2012-04-30 18:59:30 +04:00
2012-05-01 00:55:56 +04:00
fig[0] = (Figure *) Square_new (1);
fig[1] = (Figure *) ColoredSquare_new (2, 2);
2012-04-30 18:59:30 +04:00
2012-05-01 00:55:56 +04:00
((ColoredSquare *) fig[1])->vtable->set_color ((ColoredSquare *) fig[1], 5);
((Square *) fig[0])->vtable->resize ((Square *) fig[0], 2);
((Square *) fig[1])->vtable->resize ((Square *) fig[0], 3);
2012-04-30 18:59:30 +04:00
2012-04-30 19:31:40 +04:00
fig[2] = fig[1]->vtable->clone (fig[1]);
2012-05-01 00:55:56 +04:00
((ColoredSquare *) fig[2])->vtable->set_color ((ColoredSquare *) fig[2], 3);
2012-04-30 18:59:30 +04:00
2012-04-30 19:31:40 +04:00
for (i = 0; i < sizeof (fig) / sizeof (Figure *); i++)
{
2012-04-30 19:34:43 +04:00
puts ("---");
printf ("type = %s\n", fig[i]->vtable->type (fig[i]));
2012-04-30 18:59:30 +04:00
2012-04-30 19:31:40 +04:00
fig[i]->vtable->draw (fig[i]);
printf ("area(%lu) = %f\n",
(unsigned long) fig[i],
fig[i]->vtable->area (fig[i]));
printf ("diag_length(%lu) = %f\n",
(unsigned long) fig[i],
2012-05-01 00:55:56 +04:00
((Square *) fig[i])->vtable->diag_length ((Square *) fig[i]));
2012-04-30 19:31:40 +04:00
}
2012-04-30 19:34:43 +04:00
puts ("---");
2012-04-30 18:59:30 +04:00
/*goto end;
err:
end:*/
2012-04-30 19:32:41 +04:00
for (i = 0; i < sizeof (fig) / sizeof (Figure *); i++)
{
fig[i]->vtable->destroy (fig[i]);
}
2012-04-30 18:59:30 +04:00
return 0;
}