國立暨南國際大學 100 學年度第二學期小考試卷                   (考試時間: 9:30-9:50)
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2012.5.11
  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).
    // Size of an object with static members
    #include <iostream>
    #include <string>

    using std::cout;
    using std::endl;
    using std::string;

    class MyView
    {
    public:
    char type[12];
    MyView* nextView;
    static MyView* firstView;
    static MyView* lastView;

    MyView(const char* str)
    { cout << str << " view is created.\n";
    strcpy(type, str);
    if (firstView == NULL)
    firstView = lastView = this;
    else
    {
    lastView->nextView = this;
    lastView = this;
    }
    nextView = NULL;
    }
    };

    MyView* MyView::firstView = NULL;
    MyView* MyView::lastView = NULL;

    int main()
    {
    MyView view1("Bar Chart");
    MyView view2("Line Chart");
    MyView* p;
    // for (p=view1.firstView; p; p = p->nextView)
    // cout << p->type << endl;
    cout << sizeof(MyView) << endl;
    return 0;
    }
  2. 江蕙所演唱的「落雨聲」是
    1. 周杰倫作詞,方文山作曲
    2. 周杰倫作詞,周杰倫作曲
    3. 方文山作詞,方文山作曲
    4. 方文山作詞,周杰倫作曲


  3. (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).
    // Overloading the increment operator
    #include <iostream>
    #include <string>

    using std::cout;
    using std::endl;
    using std::string;
    using std::ostream;

    class Word
    {
    private:

    public:
    string word;
    Word(): word("A") {} ;

    Word& operator++()
    {
    word.insert(0, "B");
    return *this;
    }

    const Word operator++(int)
    {
    Word w = *this;
    word.append("C");
    return w;
    }

    void Print()
    { cout << word << endl; }

    friend ostream& operator<<(ostream& os, Word a) // P.569
    { os << a.word;
    return os;
    }

    };

    int main()
    {
    Word a;
    ++a; a.Print();
    a++; a.Print();
    return 0;
    }