题目1: 将以下代码拷贝到工程中:
//////////////////////////////////////////////////////////////////////
#include <vector>
class CMShape
{
public:
CMShape();
virtual void Output();
};
class CMPoint
{
public:
virtual void Output() {
std::cout << "点:" << "坐标:" << x <<" "<< y<<endl;
}
double x, y;
};
//多段线
class CMPolyLine
{
public:
void AddPoint(CMPoint &pt); //增加一个点
void AddPointArray(CMPoint* lpPt, int numPts);
vector<CMPoint> m_pts;
};
//多边形,从多段线继承
class CMPolyRegion : public CMPolyLine
{
};
//请根据以下调用代码,补充完善前面的类接口
void main()
{
vector<CMShape*> shapesData;
CMPoint pt1(1.0, 0, 0);
CMPoint pt2(2.0, 0, 0);
CMPoint pt3(2.0, 0, 0);
CMPolyLine polyLine;
polyLine.AddPoint(pt1);
polyLine.AddPoint(pt2);
polyLine.AddPoint(pt3);
CMPolyLine polyLine2; //表示多段线在后面追加一个点
polyLine2 = polyLine + CMPoint(5.0, 5.0);
//"拷贝": 将多段线的数据拷贝给多边形对象
CMPolyRegion region;
region = polyLine;
//将三个对象的指针加入数组中
shapesData.push_back(&polyLine);
shapesData.push_back(&polyLine2);
shapesData.push_back(®ion);
//输出数据
for(int i=0; i<shapesData.size(); i++)
{
shapesData[i]->Output();
}
}
///////////////////////////////////////////////////////////////////////
// 题目2
完成一个多计时器功能的类
功能:一个记时名称,起始时间,结束时间,
输出该记时
用例:
记录 "跑道1", 开始,结束,输出时间, 按时分秒输出
并输出调用例子: 输出用cout 输出
CMyTimer
{
...
}
CMyTime time;
time.Start("跑道1");
time.End("跑道1") ;
time.Output("跑道1");
time_t t1 =clock();
time_t t2 =clock();
ti-t2