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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2014.4.8
系所別:
年級:
學號:
姓名:
考試時間 14:10-14:20
  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).
    // Pass-by-Pointer
    #include <iostream>

    void swap(int &i, int &j)
    {
        int temp;
        temp = i;
        i = j;
        j = temp;
        return;
    }

    int main()
    {
        int a = 4;
        int b = 8;
        std::cout << a << b << std::endl;
        swap(&a, &b);
        std::cout << a << b << 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).
    // Recursive Function
    #include <iostream>

    void f(int i)
    {
        if (i >= 7)
            f( i / 7 );
        std::cout << i % 7;
        return;
    }

    int main()
    {
        f(50);
        std::cout << std::endl;
        return 0;
    }