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

    class CBox
    {
    protected:
    int volume;
    public:
    CBox(int v = 0): volume(v) {}
    int Volume() { return volume; }
    void ShowVolume() { cout << Volume() << '\n'; }
    };

    class CGlassBox: public CBox
    {
    public:
    CGlassBox(int v = 0): CBox(v) {}
    int Volume() { return 0.25*volume; }
    };

    int main()
    {
    CBox myBox(24);
    CGlassBox yourBox(24);
    myBox.ShowVolume();
    yourBox.ShowVolume();
    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).
    // Virtual Function
    #include <iostream>
    using std::cout;

    class CBox
    {
    protected:
    int volume;
    public:
    CBox(int v = 0): volume(v) {}
    virtual int Volume() { return volume; }
    virtual void ShowVolume() { cout << Volume() << '\n'; }
    };

    class CGlassBox: public CBox
    {
    public:
    CGlassBox(int v = 0): CBox(v) {}
    virtual int Volume() { return 0.25*volume; }
    virtual void ShowVolume() { cout << Volume() << '\n'; }
    };

    int main()
    {
    CBox myBox(24);
    CGlassBox yourBox(24);
    myBox.ShowVolume();
    yourBox.ShowVolume();
    return 0;
    }