國立暨南國際大學 101 學年度第二學期小考試卷                   (考試時間: 14:10-14:20)
科目名稱:程式設計 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2013.4.30
  1. (10%) Determine whether the following code has syntax errors or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Static data members
    #include <iostream>
    using std::cout;
    using std::endl;

    class CNode
    {
    public:
        int value;
        CNode* previous;
        static CNode* pLastNode;

        CNode(int v) :
        value(v), previous(pLastNode)
        { pLastNode = this; }
    };

    CNode* CNode::pLastNode = NULL;

    int main()
    {
        CNode a(3), b(5), c(7), d(9), e(11);
        CNode* p;
        int n = 0;

        for (n=0, p=&d; p!=NULL; p=p->previous)
            n++;
        cout << n << endl;
       
        return 0;
    }



  2. (10%) If we replace the OnDraw() function in P.953 as below, what result will be shown on the screen after you run the program?  Please specify the coordinates of endpoints of each segment, or the coordinates of centers and boundaries.

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

        const int R = 100;
        CPoint a[4] = { CPoint(R, 0), CPoint(0, R),
                        CPoint(-R, 0), CPoint(0, -R) };
        CPoint origin(200, 200);
       
        pDC->MoveTo( origin + a[0] );
        pDC->LineTo( origin + a[1] );
        pDC->MoveTo( origin + a[2] );
        pDC->LineTo( origin + a[3] );
    }