Mid-Term Exam (3)
C++ Programming
NCNU CSIE

Date: May 19th, 2010
Time: 14:10-16:00
Open book; turn off computer & mobile phone

  1. (20%) Consider the OnLButtonUP() function in P.891 (P.753 in old textbooks), if we remove the following two lines, how will the program behave differently?

    delete m_pTempElement;
    m_pTempElement = 0;

  2. (20%) Consider the OnUpdateElementRectangle() function in P.826 (P.699 in old textbooks), if we modify its definition as follows, how will the program behave differently?
    void CSketcherDoc::OnUpdateElementRectangle(CCmdUI *pCmdUI)
    {
    pCmdUI->SetCheck(m_Element == RECTANGLE);

    if (m_Element == RECTANGLE)
    {
    pCmdUI->SetText(L"RECTANGLE");
    }
    else
    {
    pCmdUI->SetText(L"rectangle");
    }
    }

  3. (20%) If we did not modify the OnUpdateElementRectangle() function in P.826 (P.699 in old textbooks), but modify the definition of OnUpdateElementLine() as follows, what will happen when you select Element-Circle?  What will happen when you select Element-Rectangle
    void CSketcherDoc::OnUpdateElementLine(CCmdUI *pCmdUI)
    {
    pCmdUI->SetCheck(m_Element == RECTANGLE);

    if (m_Element == RECTANGLE)
    {
    pCmdUI->SetText(L"RECTANGLE");
    }
    else
    {
    pCmdUI->SetText(L"rectangle");
    }
    }
  4. (20%) If we replace the OnDraw() function in P.854 (P.715 in old textbooks) as below, what result will be shown on the screen after you run the program?  Please specify the coordinates of endpoints of each segment.
    void CSketcherView::OnDraw(CDC* pDC)
    {
    CSketcherDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
    return;

    CRect aRect(50, 100, 100, 50);
    aRect.NormalizeRect();
    pDC->MoveTo(aRect.left, aRect.top);
    pDC->LineTo(aRect.right, aRect.bottom);
    }

  5. (20%) If we replace the OnDraw() function in P.854 (P.715 in old textbooks) as below, what expression should be filled in the blank if we want to obtain the following figure?
    void CSketcherView::OnDraw(CDC* pDC)

    {
        CSketcherDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        if (!pDoc)
            return;

        for (int i=10; i<=50; i+=10)
    pDC->Rectangle(CRect(CPoint(i,i), ___________ ));
    }

    Rectangles