國立暨南國際大學 101 學年度第二學期小考試卷                   (考試時間: 08:10-08:20)
科目名稱:程式設計 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2013.3.8
  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).
    // Destructor
    #include <iostream>
    using std::endl;
    using std::cout;

    class CData
    {
        public:
            int* pdata;

        CData(int n=0)
        {
            pdata = new(int);
            *pdata = n;
            cout << "Constructor called with initial value " << n << endl;
        }

        ~CData()
        {
            cout << "Destructor called to release the memory storing "
                    << *pdata << endl;
            delete pdata;
        }
    };


    int main()
    {
        CData a(3);
        CData b;
        CData c(8);
        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).
    // Function Overloading (P.310)
    #include <iostream>

    int pdo_it(int a, int b, int c)
    { return a + b + c; }

    int pdo_it(int a, int b)
    { return a * b; }

    int main()
    {
        std::cout << pdo_it(3, 8) << std::endl;
        std::cout << pdo_it(2013, 3, 8) << std::endl;
        std::cout << pdo_it( pdo_it(20,13), 13, 18 ) << std::endl;
        return 0;
    }