Void TFigure :: setcol ( int c )
{ color = c; }
Void TFigure :: setwidth ( int w )
{ width = w; }
void TFigure :: setnum_p ( int n )
{ num_p = n; }
Int TFigure :: getwidth ( void )
{ return width; }
Int TFigure :: getcol ( void )
{ return color; }
Void TFigure :: setxy ( int n, int xn, int yn )
{ x[n] = xn;
y[n] = yn;
}
Int TFigure :: getxn ( int n )
{ return x[n]; }
Int TFigure :: getyn ( int n )
{ return y[n]; }
Class Circle : public TFigure
{ private:
int rad;
public:
Circle ( int x, int y, int r );
virtual void draw ( void );
};
Circle :: Circle ( int a, int b, int r )
{ setnum_p ( 1 );
setxy ( 0, a, b );
rad = r;
}
Void Circle :: draw ( void )
{ setlinestyle ( 0, 0, getwidth() );
setcolor ( getcol() );
circle ( getxn ( 0 ), getyn ( 0 ), rad );
}
Class Triangle : public TFigure
{ public:
virtual void draw ( void );
Triangle ( int a1, int b1, int a2, int b2, int a3, int b3 );
};
Triangle :: Triangle ( int a1, int b1, int a2, int b2, int a3, int b3 )
{ setnum_p ( 3 );
setxy ( 0, a1, b1 );
setxy ( 1, a2, b2 );
setxy ( 2, a3, b3 );
}
Void Triangle :: draw ( void )
{ setlinestyle ( SOLID_LINE, 1, getwidth() );
setcolor ( getcol() );
line ( getxn(0), getyn(0), getxn(1), getyn(1) );
line ( getxn(1), getyn(1), getxn(2), getyn(2) );
line ( getxn(0), getyn(0), getxn(2), getyn(2) );
}
Main ()
{ Circle c1( 320, 240, 150 );
Circle c2( 320, 240, 50 );
Triangle t1( 100, 100, 400, 150, 250, 300 );
Triangle t2( 400, 400, 600, 400, 500, 300 );
TFigure *pf=&t2;
int grmode, grdriver=DETECT;
initgraph ( &grdriver, &grmode, "" );
c1.setcol ( MAGENTA );
c1.setwidth ( NORM_WIDTH );
c1.draw ();
c2.setcol ( GREEN );
c2.setwidth ( THICK_WIDTH );
c2.draw ();
t1.setcol ( YELLOW );
t1.setwidth ( NORM_WIDTH );
t1.draw ();
pf->setcol ( BLUE );
pf->setwidth ( THICK_WIDTH );
pf->draw ();
bioskey(0);
closegraph();
return 0;
}
// ПРОГРАММА FIGURES5
#include <graphics.h>
#include <bios.h>
#define MAX_POINTS 4
// *************************************
Class TFigure
{ private:
int color;
int width;
int num_p;
int x[MAX_POINTS];
int y[MAX_POINTS];
public:
virtual void draw ( void ) = 0;
void setcol ( int c );
void setwidth ( int w );
void setnum_p ( int n );
void setxy ( int n, int xn, int yn );
int getcol ( void );
int getwidth ( void );
int getxn ( int n );
int getyn ( int n );
};
Void TFigure :: setcol ( int c )
{ color = c; }
Void TFigure :: setwidth ( int w )
{ width = w; }
void TFigure :: setnum_p ( int n )
{ num_p = n; }
Int TFigure :: getwidth ( void )
{ return width; }
Int TFigure :: getcol ( void )
{ return color; }
Void TFigure :: setxy ( int n, int xn, int yn )
{ x[n] = xn;
y[n] = yn;
}
Int TFigure :: getxn ( int n )
{ return x[n]; }
Int TFigure :: getyn ( int n )
{ return y[n]; }
// ************************************
Class Circle : public TFigure
{ private:
int rad;
public:
Circle ( int x, int y, int r );
virtual void draw ( void );
};
Circle :: Circle ( int a, int b, int r )
{ setnum_p ( 1 );
setxy ( 0, a, b );
rad = r;
}
Void Circle :: draw ( void )
{ setlinestyle ( 0, 0, getwidth() );
setcolor ( getcol() );
circle ( getxn ( 0 ), getyn ( 0 ), rad );
}
// ***************************************
Class Triangle : public TFigure
{ public:
virtual void draw ( void );
Triangle ( int a1, int b1, int a2, int b2, int a3, int b3 );
};
Triangle :: Triangle ( int a1, int b1, int a2, int b2, int a3, int b3 )
{ setnum_p ( 3 );
setxy ( 0, a1, b1 );
setxy ( 1, a2, b2 );
setxy ( 2, a3, b3 );
}
Void Triangle :: draw ( void )
{ setlinestyle ( SOLID_LINE, 1, getwidth() );
setcolor ( getcol() );
line ( getxn(0), getyn(0), getxn(1), getyn(1) );
line ( getxn(1), getyn(1), getxn(2), getyn(2) );
line ( getxn(0), getyn(0), getxn(2), getyn(2) );
}
// ***************************************
Main ()
{ Circle c1( 320, 240, 150 );
Circle c2( 320, 240, 50 );
Triangle t1( 100, 100, 400, 150, 250, 300 );
Triangle t2( 400, 400, 600, 400, 500, 300 );
TFigure *pf[4];
int grmode, grdriver=DETECT, i, key;
initgraph ( &grdriver, &grmode, "" );
pf[0] = &c1;
pf[1] = &c2;
pf[2] = &t1;
pf[3] = &t2;
pf[3]->setcol ( BLUE );
pf[3]->setwidth ( THICK_WIDTH );
for (i=0; i<4; i++ )
{ pf[i]->setcol ( MAGENTA + i*2 );
pf[i]->setwidth ( NORM_WIDTH );
pf[i]->draw ();
}
key = bioskey(0);
closegraph();
return 0;
}
// ПРОГРАММА FIGURES6
#include <graphics.h>
#include <bios.h>
#define MAX_POINTS 4
// *************************************
Class TFigure
{ private:
int color;
int width;
int num_p;
int x[MAX_POINTS];
int y[MAX_POINTS];
public:
virtual void draw ( void ) = 0;
void setcol ( int c );
void setwidth ( int w );
void setnum_p ( int n );
void setxy ( int n, int xn, int yn );
int getcol ( void );
int getwidth ( void );
int getxn ( int n );
int getyn ( int n );
};
Void TFigure :: setcol ( int c )
{ color = c; }
Void TFigure :: setwidth ( int w )
{ width = w; }
void TFigure :: setnum_p ( int n )
{ num_p = n; }
Int TFigure :: getwidth ( void )
{ return width; }
Int TFigure :: getcol ( void )
{ return color; }
Void TFigure :: setxy ( int n, int xn, int yn )
{ x[n] = xn;
y[n] = yn;
}
Int TFigure :: getxn ( int n )
{ return x[n]; }
Int TFigure :: getyn ( int n )
{ return y[n]; }
// ************************************
Class Circle : public TFigure
{ private:
int rad;
public:
Circle ( int x, int y, int r );
virtual void draw ( void );
};
Circle :: Circle ( int a, int b, int r )
{ setnum_p ( 1 );
setxy ( 0, a, b );
rad = r;
}
Void Circle :: draw ( void )
{ setlinestyle ( 0, 0, getwidth() );
setcolor ( getcol() );
circle ( getxn ( 0 ), getyn ( 0 ), rad );
}
// ***************************************
Class Triangle : public TFigure
{ public:
virtual void draw ( void );
Triangle ( int a1, int b1, int a2, int b2, int a3, int b3 );
};
Triangle :: Triangle ( int a1, int b1, int a2, int b2, int a3, int b3 )
{ setnum_p ( 3 );
setxy ( 0, a1, b1 );
setxy ( 1, a2, b2 );
setxy ( 2, a3, b3 );
}
Void Triangle :: draw ( void )
{ setlinestyle ( SOLID_LINE, 1, getwidth() );
setcolor ( getcol() );
line ( getxn(0), getyn(0), getxn(1), getyn(1) );
line ( getxn(1), getyn(1), getxn(2), getyn(2) );
line ( getxn(0), getyn(0), getxn(2), getyn(2) );
}
// ***************************************
#define NUM_F 4
Main ()
{ Circle c1( 320, 240, 150 );
Circle c2( 320, 240, 50 );
Triangle t1( 100, 100, 400, 150, 250, 300 );
Triangle t2( 400, 400, 600, 400, 500, 300 );
TFigure *pf[NUM_F];
int grmode, grdriver=DETECT, i, key;
initgraph ( &grdriver, &grmode, "" );
pf[0] = &c1;
pf[1] = &c2;
pf[2] = &t1;
pf[3] = &t2;
for (i=0; i<NUM_F; i++ )
{ pf[i]->setcol ( MAGENTA + i*2 );
pf[i]->setwidth ( NORM_WIDTH );
pf[i]->draw ();
}
i = -1;
do { key = bioskey(0);
if ( key == 0x0F09 ) // Tab
{ i++;
if ( i == NUM_F )
i = 0;
pf[i]->setcol ( pf[i]->getcol() + 1 );
pf[i]->setwidth ( THICK_WIDTH );
pf[i]->draw ();
}
} while ( key != 0x011B ); // Esc
closegraph();
return 0;
}
// ПРОГРАММА FIGURES7
#include <graphics.h>
#include <bios.h>
#define MAX_POINTS 4
#define STEP 10
// *************************************
Class TFigure
{ private:
int color;
int width;
int num_p;
int x[MAX_POINTS];
int y[MAX_POINTS];
public:
virtual void draw ( void ) = 0;
void move ( int k );
void setcol ( int c );
void setwidth ( int w );
void setnum_p ( int n );
void setxy ( int n, int xn, int yn );
int getcol ( void );
int getwidth ( void );
int getxn ( int n );
int getyn ( int n );
};