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

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

(考試時間: 10:10-10:30)


  1. (10%) 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).
    #include <iostream>
    using std::cout;

    class CNumber
    {
    public:
    CNumber(int v)
    {
    cout << "A number is created with value: " << (m_value = v)
    << "\n";
    }

    int m_value;
    };

    int main()
    {
    CNumber a(1);
    CNumber* pv1 = new CNumber(2);
    CNumber* pv2 = new CNumber(3);
    cout << "The value of m_value is " << pv2->m_value << "\n";
    }








  2.  (10%) What output shall we see if we add the following destructor to the above code?

    ~CNumber()
    {
    cout << "The object containing " << m_value <<
    " is destroyed.\n";
    }