國立暨南國際大學 97 學年度第一學期小考試卷

科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2009.4.15

(考試時間: 16:20-16:40)


  1. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    #include <iostream>
    using std::cout;

    class CNumber
    {
    public:
    CNumber(int v)
    {
    cout << "A number is created with value: " << (m_value = v)
    << "\n";
    }

    ~CNumber()
    {
    cout << "The object containing " << m_value
    << " is destroyed.\n";
    }

    int m_value;
    };

    int main()
    {
    CNumber a(1);
    CNumber* pv1 = new CNumber(2);
    CNumber* pv2 = new CNumber(3);
    cout << "The value of m_value is " << *pv2.m_value << "\n";
    }






  2. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).

    #include <iostream>
    using std::cout;

    class CList
    {
    public:
        int data;
        CList* next;

        CList(int n, CList* p);
    };

    int main()
    {
        CList c(3, NULL);
        CList b(2, &c);
        CList a(1, &b);

        CList* p = &a;
        while (p != NULL)
        {
            cout << p->data << "\n";
            p = p->next;
        }
    }

    CList::CList(int n, CList* p)
    {
        data = n;
        next = p;
    }