#include"iostream"
#include"string.h"
using namespace std;
class CPoint
{
private:
int X;
int Y;
public:
CPoint(int x = 0, int y = 0)
{
X = x, Y = y;
}
CPoint(CPoint &p)
{
X = p.X;
Y = p.Y;
}
int GetX()
{
return X;
}
int GetY()
{
return Y;
}
};
class CShape
{
private:
char Color[10];
public:
CShape(char*c)
{
strcpy(Color, c);
}
void Draw()
{
cout << "Draw a shape.The color is" << Color << endl;
}
void PrintColor()
{
cout << Color << endl;
}
};
class CLine :public CShape
{
private:
CPoint Start;
CPoint End;
public:
CLine(CPoint s, CPoint e, char*c) : CShape(c), Start(s), End(e)
{}
void Draw()
{
cout << "Draw a Line from(" << Start.GetX() << "," << Start.GetY();
cout << ")to(" << End.GetX() << "," << End.GetY() << "),with color";
PrintColor();
}
};
class CCircle :public CShape
{
private:
CPoint Center;
int Radius;
public:
CCircle(CPoint ctr, int r, char *c) :CShape(


uj5u.com熱心網友回復:
題目:定義一個點類CPoint,資料成員有點的坐標,再定義一個幾何形狀類CShape,資料成員只有顏色,以CShape類為基類派生出線段類CLine和圓類CCircle,其中線段類CLine的資料成員包括起點和終點(為CPoint類的子物件),圓類CCircle的資料成員包括圓心(為CPoint類的子物件)和半徑。uj5u.com熱心網友回復:
建構式CShape(char*c)改成 CShape(const char*c) 試試
uj5u.com熱心網友回復:
nice,完美解決轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/12644.html
標籤:C++ 語言
上一篇:C++怎么創建介面啊?
