谁帮我做下这几道编程题 用C++ 感激不尽!

2024-12-21 14:33:12
推荐回答(2个)
回答1:

class CDrawAttr
{
protected:
DWORD m_color;
float m_penWidth;
WORD m_wFlag;
public:
void Remove() { m_wFlag |= 0x8000; } // 设置最高位
void Restore() { m_wFlag &= 0x7FFF; }; // 清除最高位
virtual void Draw(CDC* pDC) = 0;
virtual ~CDrawAttr() { }
}

class CLine : public CDrawAttr
{
POINT m_pt1, m_pt2;
public:
CLine(POINT p1, POINT p2, DWORD dwColor, float nPenWidth)
{
m_pt1 = p1;
m_pt2 = p2;
m_color = dwColor;

m_penWidth = nPenWidth;
}
virtual void Draw(CDC* pDC)

{

pDC->DrawLine(m_pt1, m_pt2, m_color, m_penWidth ); // 伪代码
}

}

class CRectangle : public CDrawAttr
{
POINT m_ptLeftTop, m_ptRightDown;
public:
CLine(POINT p1, POINT p2, DWORD dwColor, float nPenWidth)
{
m_ptLeftTop = p1;
m_ptRightDown = p2;
m_color = dwColor;
m_penWidth = nPenWidth;
}
virtual void Draw(CDC* pDC)
{
pDC->DrawRect(m_ptLeftTop , m_ptRightDown , m_color, m_penWidth ); // 伪代码
}
}

void main()
{
CLine line(...);

CRectangle rect(...);

CDrawAttr* pDrawObject[] = { &line, &rect };

for(int i = 0; i < countof(pDrawObject); i++)

{

pDrawObject[i]->Draw();

}
}

回答2:

据说只需要百度下你就能够找到相似的代码!