Final Exam (2nd Chance)
C++ Programming
NCNU CSIE

Date: June 25th, 2010
Time: 8:30-9:30
Open book; turn off mobile phone



  1. If we replace the OnDraw()function in P.854 (P.715 in the old textbook) as below,

    void insert(CList<CPoint, CPoint&>& L, CPoint P)
    {
        POSITION aPos = L.GetHeadPosition();
        while (aPos)
        {
            CPoint CurrentPoint = L.GetAt(aPos);
            if (P.x < CurrentPoint.x)
            {
                L.InsertBefore(aPos, P);
                return;
            }           
            else
                L.GetNext(aPos);
        }
        L.AddTail(P);   
    }

    void CSketcherView::OnDraw(CDC* pDC)
    {
        CSketcherDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        if (!pDoc)
            return;

        CList<CPoint, CPoint&> PointList;
        insert(PointList, CPoint(20,100) );
        insert(PointList, CPoint(80,100) );
        insert(PointList, CPoint(30,150) );  
        insert(PointList, CPoint(70,150) );
        insert(PointList, CPoint(90,200) );
        insert(PointList, CPoint(10,200) );
        insert(PointList, CPoint(50,10) );

        POSITION aPosition = PointList.GetHeadPosition();
        if (aPosition)
            pDC->MoveTo(PointList.GetNext(aPosition));
        pDC->LineTo(PointList.GetAt(aPosition));

        while (aPosition)          
            pDC->LineTo(PointList.GetNext(aPosition));
       
        pDC->LineTo(PointList.     (1)     (PointList.     (2)     ()) );   
    }


    If we want to obatin the following results, what function names should be filled into the two blanks, respectively?

    Curve
  2. Design a program to draw the following game.