國立暨南國際大學 98 學年度第二學期小考試卷

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

(考試時間: 14:10-14:25)


  1. (10%) Suppose we have the following two files ("box.h" and "box-1.cpp").  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).

    // box.h
    #include <iostream>
    using std::cout;

    class CBox {

    public:
        int weight;

        CBox(int w=0) : weight(w)
        { cout << "Constructor called.\n"; }
        CBox(CBox& aBox)
        { cout << "Copy Constructor called.\n";
          this->weight = aBox.weight;
        }
    };


    // box-1.cpp
    #include "box.h"

    int main()
    {
        CBox box1(10);
        CBox box2;
        cout << box2.weight << "\n";
        box2 = box1;
        cout << box2.weight << "\n";
    }