一道C++试题,急求正确答案。

这是本周六考试的题目,现急求正确答案,希望有能力者,测试出正确答案。全部积分奉上。。谢过。。
1.在二维坐标系上定义GRAPH抽象类,该类具有基点坐标和图形显示等纯虚函数。从该类派生出三角形,圆形,和四边形等特定图形类,从圆类和三角形类派生出圆内接三角形类,并为特定图形类定义相应纯虚函数。定义每一个类的构造函数,析构函数,绘图函数以及相应的数据成员。
设计Draw类,其中设计一个数组数据成员存放各种图形对象,设计一个方法绘出每个图形的形状。
希望有能力者上,本人很急。
老师发的word文档,这就是原题。
我只知道是这个题,应该没有其它的要求吧。
程序有多大呢?

下面是我写的,合你的意吗?

#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;
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-04-16
无能为力
第2个回答  2008-04-16
我们以前做过这个类似的题型,不过比我们涉及的东西要多啊.这里涉及到的类及抽象类,纯虚函数及其他函数,还有数据成员都是C++比较核心的部分,程序真的很复杂.找人一起帮你看看去...
第3个回答  2008-04-19
函数太大,需要MFC无法上传啊
第4个回答  2008-04-19
#include using namespace std;
class Graph{
protected:
int x;
int y;
public:
Graph(int x=0, int y=0) :x(x),y(y) {}
virtual void input();
virtual void draw()
{
cout<<"nothing"<> x >> y;
}
class Line : public Graph
{
protected:
int endx;
int endy;
public:
Line( int a=0, int b=0, int c=0, int d=0 )
:Graph(a,b),endx(c),endy(d) {}
virtual void input();
virtual void draw();
virtual ~Line(){}
};
void Line::input()
{
cout << "Line, ";
Graph::input();
cout << "input x and y of endpoint:";
cin >> endx >> endy;
}
void Line::draw()
{
cout << "Line" << x << ';,'; << y << ")-(" << endx << ';,';<< endy << ';)'; << endl;
}
class Circle : public Graph
{
protected:
int r;
public:
Circle(int a=0, int b=0, int c=0) :Graph(a,b),r(c) {}
void input();
void draw();
~Circle(){}
};
void Circle::input()
{
cout << "Circle, ";
Graph::input();
cout << "input radius:";
cin >> r;
}
void Circle::draw()
{
cout << "Circle" << x << ';,'; << y << ")*" << r << endl;
}
int main(int argc, char* argv[])
{
Line ol;
Circle oc;
Graph mm;
Graph* p=NULL;
p=&mm;
p->draw();
p = &ol;
p->input();
p->draw();
p = &oc;
p->input();
p->draw();
for(;;)
{
cout << "(1)Line\t(2)Circle" <> choice;
if( choice==1 )
p = new Line;
else if( choice==2 )
p = new Circle;
else
return 0;
p->input();
p->draw();
delete p;
}
return 0;
}
第5个回答  2008-05-03
要去理解,考高分不是重点,我以前c++都考试不及格的,现在在我们专业编程怎么的也在中上游的水平了,加油
相似回答
大家正在搜