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

科目名稱:程式設計 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2009.6.3

(考試時間: 14:10-14: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;
    using std::endl;

    class CCounter // Pure Virtual Function
    {
    protected:
    int counter;
    virtual void Put(int i) = 0;
    int Get() { return counter; }
    public:
    void Init(int i) { Put(i); }
    void Show() { cout << Get() << "\n"; }
    };

    class CBigCounter : public CCounter
    {
    protected:
    virtual void Put(int i) { counter = i * 10; }
    public:

    };

    int main()
    {
    CCounter c1;
    CBigCounter c2;
    c1.Init(5); c1.Show();
    c2.Init(5); c2.Show();
    }