Tuesday, May 25, 2010

Draw circle and rectangle using inheritance

#include
#include
#include
#include
#include
class Base
{
public:
void crcle ()
{
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int radius = 100;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
circle(midx, midy, radius);
getch();
}
void recangle()
{
int gdriver = DETECT, gmode, errorcode;
int left, top, right, bottom;

initgraph(&gdriver, &gmode, "");

errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

left = getmaxx() / 2 - 50;
top = getmaxy() / 2 - 50;
right = getmaxx() / 2 + 50;
bottom = getmaxy() / 2 + 50;

/* draw a rectangle */
rectangle(left,top,right,bottom);
getch();
}
} ;
class Der : public Base
{

public:
void Process()
{
crcle();

recangle();
}
} d ;
int main(void)
{
d.Process();
return 0;
}

No comments:

Post a Comment