國立暨南國際大學 100 學年度第二學期小考試卷                   (考試時間: 14:10-14:20)
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2012.3.14
  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).
    // Using a static data member in a class
    #include <iostream>
    using std::cout;

    class CData
    {
    private:
        static int count;    // Can it be a private member?
    public:
        CData()  { ++count; }
        ~CData() { --count; }
        void ShowIt() { cout << count << '\n'; }
    };

    int CData::count = 0;

    int main()
    {
        CData apple[2];
        apple[0].ShowIt();
        CData iphone[4];
        iphone[0].ShowIt();
        return 0;
    }



  2. (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).
    // When is Destructor called?
    #include <iostream>
    using std::cout;

    class CData
    {
    private:
        static int count;   
    public:
        CData()  { ++count; }
        ~CData() { --count; }
        void ShowIt() { cout << count << '\n'; }
    };

    int CData::count = 0;

    void test1()
    {
        CData apple[2];
        apple[0].ShowIt();
    }

    void test2()
    {
        CData iphone[4];
        iphone[0].ShowIt();
    }

    int main()
    {
        test1();   
        test2();
        return 0;
    }