下面是我写的,合你的意吗?
#include <iostream.h>
class Graph
{
protected:
int x;
int y;
public:
Graph(int X=0, int Y=0)
{
x=X;y=Y;
}
virtual void draw()=0;
~Graph(){}
};
//三角形
class Triangle : public Graph
{
protected:
int x2,y2,x3,y3;
public:
Triangle(int X1=0, int Y1=0, int X2=0,int Y2=0,int X3=0,int Y3=0)
{
x=X1;y=Y1;
x2=X2;y2=Y2;
x3=X3;y3=Y3;
}
void draw()
{
cout << "Triangle("<<x<<","<<y<<";"<<x2<<","<<y2<<";"<<x3<<","<<y3<<")"<<endl;
}
~Triangle(){}
};
//圆形
class Circle : public Graph
{
protected:
int r;
public:
Circle(int X=0, int Y=0, int R=0)
{
x=X;y=Y;
r=R;
}
void draw()
{
cout << "Circle("<<x<<","<<y<<";"<<r<<")"<<endl;
}
~Circle(){}
};
//四边形
class Quadrangle : public Graph
{
protected:
int x2,y2,x3,y3,x4,y4;
public:
Quadrangle(int X1, int Y1, int X2,int Y2,int X3,int Y3,int X4,int Y4)
{
x=X1;y=Y1;
x2=X2;y2=Y2;
x3=X3;y3=Y3;
x4=X4;y4=Y4;
}
void draw()
{
cout << "Quadrangle("<<x<<","<<y<<";"<<x2<<","<<y2<<";"<<x3<<","<<y3<<";"<<x4<<","<<y4<<")"<<endl;
}
~Quadrangle(){}
};
//圆内接三角形
class TriangleInCircle:public Circle,public Triangle
{
public:
TriangleInCircle(int X1, int Y1, int X2,int Y2,int X3,int Y3)
{
Triangle::x=X1;
Triangle::y=Y1;
x2=X2;y2=Y2;
x3=X3;y3=Y3;
//外接圆的半径和圆心,可以由上面3点确定的
}
void draw()
{
cout << "TriangleInCircle("<<Triangle::x<<","<<Triangle::y<<";"<<x2<<","<<y2<<";"<<x3<<","<<y3<<")"<<endl;
}
~TriangleInCircle(){}
};
int main()
{
Triangle t(1,1,2,2,3,3);
Circle c(1,1,5);
Quadrangle q(1,1,2,2,3,3,4,4);
TriangleInCircle tc(3,3,2,2,1,1);
Graph *g[4];
g[0]=&t;
g[1]=&c;
g[2]=&q;
g[3]=(Circle*)&tc;
for(int i=0;i<4;i++)
{
g[i]->draw();
}
return 0;
}
温馨提示:内容为网友见解,仅供参考