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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2015.4.22
系所別:
年級:
學號:
姓名:
考試時間 08:20-08:30
  1. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Default Values of Function Parameters (P.228)
    #include <iostream>
    using std::cout;
    using std::endl;

    int sum(int a = 10, int b = 20)
    {
        return a + b;
    }

    int main()
    {
        cout << sum(4, 22) << endl;
        cout << sum(4) << endl;
        return 0;
    }


  2. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Pointers to Functions (P.221)
    #include <iostream>
    using std::cout;
    using std::endl;

    int sum(int a = 10, int b = 20)
    { return a + b; }

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

    int main()
    {
        int *(pdo_it)(int, int);
        pdo_it = product;
        cout << pdo_it(4,22) << endl;
        pdo_it = sum;
        cout << pdo_it(4,22) << endl;
        return 0;
    }

  3. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Array of Pointers to Functions (P.227)
    #include <iostream>
    using std::cout;
    using std::endl;

    int sum(int a, int b)
    { return a + b; }

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

    int diff(int a, int b)
    { return a - b; }

    int main()
    {
        int (*pdo_it[3])(int, int) = {sum, diff, product};
        cout << (*(pdo_it+2))(4,22) << endl;
        cout << pdo_it[1](4,22) << endl;
        return 0;
    }

  4. (10%) Describe the three questions in "The Golden Circle" introduced by Simon Sinek's TED speech  "How great leaders inspire action". Note that you should describe the three questions from inside out, not from outside in.