國立暨南國際大學 101 學年度第一學期小考試卷

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2012.12.18
系所別:
年級:
學號:
姓名:
考試時間 16:30-16:50

  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).
    // Convert a string to a number
    #include <iostream>

    int eval(char* s)
    {
        const int base = 8;
        int sum = 0;
        while(*s)
            sum = sum * base + (*s++ - '0');
        return sum;
    }

    int main()
    {
        std::cout << eval("17") << std::endl;
        std::cout << eval("1221") << std::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).
    // 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(12, 18) << std::endl;
        std::cout << pdo_it(2012, 12, 18) << std::endl;
        std::cout << pdo_it( pdo_it(20,12), 12, 18 ) << std::endl;
        return 0;
    }